rniemeyer / knockout-jqAutocomplete

knockout-jqAutocomplete is a Knockout.js plugin designed to work with jQuery UI's autocomplete widget.
MIT License
49 stars 20 forks source link

Change value from viewModele #5

Open pavel123123 opened 10 years ago

pavel123123 commented 10 years ago

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!

gaydenko commented 10 years ago

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

damiancardozo commented 9 years ago

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

ryantheleach commented 7 years ago

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.