knockout-jqAutocomplete icon indicating copy to clipboard operation
knockout-jqAutocomplete copied to clipboard

Change value from viewModele

Open pavel123123 opened this issue 11 years ago • 3 comments

I have binding on object {id:1,name:"some text"} When I write in viewModele the code this.objectValue = ko.observable(1); I see in textBox "1" instead "some text"

Can I set this.objectValue any value from ViewModel?

Thank you!

pavel123123 avatar May 07 '14 12:05 pavel123123

I guess, you want to use valueProp and labelProp and set them to id and name in your markup (see README).

gaydenko avatar May 07 '14 12:05 gaydenko

I'm having the same issue, although I defined valueProp, labelProp and inputProp.

Having this category object: {"id": "Computers", "path": "/Computers", "name": "Computers"}

if in the view model I call self.category(cat); // cat being the object above

the autocomplete displays "/Computers" instead of "Computers".

this is the code of the update method in the autocomplete:

this.update = function(element, valueAccessor) { var options = unwrap(valueAccessor()), value = unwrap(options && options.value); element.value = value; };

I debugged this in firefox, and options.value = "/Computers"

Note that if the value is selected in the autocomplete, everything works ok. the problem is when the value is updated from the model

damiancardozo avatar Nov 19 '14 14:11 damiancardozo

I had this problem when the source was an observable array, it was somehow backpopulating the array with nothing.

Using ko.toJS(vm) as the source fixed the issue however.

ryantheleach avatar Apr 27 '17 00:04 ryantheleach