Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change value from viewModele #5

Open
pavel123123 opened this issue May 7, 2014 · 3 comments
Open

Change value from viewModele #5

pavel123123 opened this issue May 7, 2014 · 3 comments

Comments

@pavel123123
Copy link

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
Copy link

gaydenko commented May 7, 2014

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

@damiancardozo
Copy link

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants