knockout.js - KnockoutJS validation plugin on viewmodel components -
my viewmodel has ko.observable
members store dialog state objects. each dialog object has sorts of members corresponding input fields in dialog. add validation dialogs using knockoutjs validation plugin.
i don't, however, want add validation entire view model, rather dialogs. when tried extending dialogs this:
this.dialog = ko.observable(new registrationdialog(self)).extend({validatable: true});
things didn't work right: isvalid() , errors() methods not defined, , validation wasn't working properly. i've created jsfiddle illustrate this. when press start button, dialog opens (pardon lack of css), pressing enter doesn't generate error messages. email validation fails work, showing message 'true not proper email address.'
i go documentation:
this.dialog = ko.validatedobservable(new registrationdialog(this));
then fix bugs in fiddle:
- data-blind
- click handler on form (instead of submit, assume)
- on register button have
enable: isvalid
shouldenable: isvalid()
(i removed click binding because of fixing form submit binding)
i think it. updated fiddle here
Comments
Post a Comment