Knockout validation of checkbox not showing message -


i have jsfiddle http://jsfiddle.net/63qje/3/ works, not show validation method.

html:

<input type="checkbox" data-bind="checked: approveterms"/> <label for="algvw">yes, agree general terms , conditions</label> <span data-bind="validationmessage: approveterms"></span> <button type="button" data-bind="click: stepforward">commit order</button> 

js:

ko.validation.rules['checkedterms'] = {     validator: function (value) {         console.log(value);         if (!value)             return false;         return true;     } }; function ovm() {     var self = this;     self.approveterms = ko.observable(false).extend({         checkedterms: { message: 'approval required' }     });     self.currentstep = ko.observable(1);     self.stepforward = function () {         if (self.currentstep() === 1)             commitorder(self);     }; } window.vm = new ovm(); ko.applybindings(vm);  function commitorder(vm) {     if (vm.approveterms())         alert("go!");     else         alert("nooooooooo"); } 

i rather new ko , still learning. have other validators on textfields , work, checkbox causing me headache.

why can't this:

self.approveterms = ko.observable(false).extend({ required: true, message:'approval req.' }); 

if creating custom validator rule need call

 ko.validation.registerextenders(); 

after custom rules in order validation plugin registers new validators.

demo jsfiddle.

or if want check checkbox checked can use built in equal validator:

self.approveterms = ko.observable(false).extend(     { equal: { params: true, message:'approval req.' }}); 

demo jsfiddle.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -