Hey guys! I experienced some problems when making checkboxes required (for example terms and conditions).
See here for reference: http://jsfiddle.net/v6d5y3or/
Expected behaviour: Form .isValid() should reflect the checkbox value: checkbox.true = form.true and checkbox.false = form.false
Actual behaviour: Form .isValid() is always true: checkbox.true = form.true and checkbox.false = form.true
I'm not really sure why this happens and one would think that required: true works together with the checked binding.
A temporary solution to me is to implement a custom validator to make it work as expected:
ko.observable(false).extend({
validation: [{
validator: (value, params) => Boolean(value)
}]
})
Hey guys! I experienced some problems when making checkboxes required (for example terms and conditions).
See here for reference: http://jsfiddle.net/v6d5y3or/
Expected behaviour: Form
.isValid()should reflect the checkbox value:checkbox.true = form.trueandcheckbox.false = form.falseActual behaviour: Form
.isValid()is always true:checkbox.true = form.trueandcheckbox.false = form.trueI'm not really sure why this happens and one would think that
required: trueworks together with thecheckedbinding.A temporary solution to me is to implement a custom validator to make it work as expected: