As cyanfic has shown, the correct way is updating the observable.
If the problem is that your code does not have access to the observable, for example, you write a bookmarklet to automatically fill out the form, then you can access the observable as follows:
function setValue(input, value) { var bindingsString = input.getAttribute('data-bind'); if (bindingsString) { var bindings = ko.bindingProvider.instance.parseBindingsString(bindingsString, ko.contextFor(input), input); if (bindings.value) { bindings.value(value); } else if (bindings.checked) { bindings.checked(value); } else { input.value = value; } } else { input.value = value; } }
Peter Agar
source share