Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Problems with .isValid() on required checkboxes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
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)
}]
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked JSFiddle reproduction and trace how required validation handles Knockout checkbox checked bindings. Compare the unchecked and checked cases against the reported expected and actual isValid() results; done means an unchecked required checkbox makes the form invalid while a checked one makes it valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100