I'm using some code I've found on SO (the second answer here: knockout.js - deferred databinding for modal?).
The details aren't displaying in the form though.
rowClick: function(data){
console.log("in row click");
console.log(data); // produces data as per debug below
// load the transaction when a row is clicked
self.EditingTransaction(data);
console.log(self.EditingTransaction()); // produces data as per debug below (not as a observable though)
},
here is the view code:
<div data-bind="modal: EditingTransaction" class="fade">
<form data-bind="submit: $root.SaveTransaction">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>
Editing transaction</h3>
</div>
<div class="modal-body">
<label>Date</label> <input type="text" data-bind="text: Date"/></br>
<label>Category</label> <input type="text" data-bind="text: Category"/></br>
<label>Subcategory</label> <input type="text" data-bind="text: Subcategory"/></br>
<label>Amount</label> <input type="text" data-bind="text: Amount"/></br>
<label>Notes</label> <input type="text" data-bind="text: Notes"/></br>
<pre data-bind="text: ko.toJSON($root.EditingTransaction, null, 2)"></pre>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary" data-bind="click: $root.SaveTransaction">Save changes</a>
</div>
</form>
</div>
The dialog is displaying when data is assigned to editTransaction - the pre ko.toJSON debug HTML displays this:
{
"ID": "1231",
"TransactionType": "Withdrawal",
"Date": "2012-11-07",
"Category": "cat",
"Subcategory": "sub cat",
"Amount": "-50.00",
"currency": "GBP",
"Notes": "",
"AccountName": "Account 2",
"Payee": "Cheque"
}
I have had a search about and seen comments about the data not being available when the modal is initialised (when page loads) but I that doesn't make sense to me (I believe the point bindings is that they update when the view when data changes and also the debug statement is working ok). I have tried without the with in the binding code and also with a reference to $root in the data-bind text.
So, any ideas why it isn't working would be great.
PICNIC :-)
The bindings on the input tag should have been value not text... I've been looking at that on and off for a day - within 10 mins of posting the answer hits me!