i read many tutorials but i dont know how to do this, this is the input
input(type=\"text\",name=\"price\",id=\"price\"data-bind=\"text: price,valueUpdate:[\
An alternative approach: I have found that Knockout works well in combination with jQuery-validate. You just need to make sure that you validate the form before you attempt to use the numeric value.
Say you have a form DOM element, you can set up validation rules via
$(".yourform").validate({
rules: {
year: {
digits: true,
minlength: 4,
maxlength: 4
}
},
messages: {
year: "Please enter four digits (e.g. 2009).",
}
});
In your viewmodel you set the two-way binding up as usual, e.g. via self.year = ko.observable("")
. Now make sure that you call $(".yourform").valid()
before you are further processing self.year()
. In my case, I am doing var year = parseInt(self.year(), 10)
. Right after form validation this is expected to always produce a meaningful result.