knockout.js - Dynamically esponsive attribute in knockoutJS -
i'm new knockoutjs , it. problem can't figure out how include sort of validation in binding. i'm trying disable button unless there text in text field.
<input type="text" name="answer" id="txtanswer" placeholder="answer..." data-bind="value: newanswer" /> <button data-inline="true" data-bind="click: addanswer, enable: newanswer() != ''" >add</button>
in viewmodel have self.newanswer = ko.observable($("#txtanswer").val())
i've tried can think of, can't make button responsive. seems evaluate once, on page load, nothing changes.
any appreciated.
your observable looks funky. don't need jquery selector inside of call observable
. link observable element via data-bind
attribute:
self.newanswer = ko.observable(''); //replace '' default value want
then markup:
<input type="text" name="answer" id="txtanswer" placeholder="answer..." data-bind="value: newanswer" />
edit
here jsfiddle demonstrate working example: http://jsfiddle.net/c6uts/
Comments
Post a Comment