Ticket #263 (closed defect: fixed)
Conditional validation of a forms control.
| Reported by: | karel | Owned by: | freya |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.4 |
| Component: | modules/kauri-forms | Version: | trunk |
| Keywords: | Cc: |
Description
Example use case:
If you check the 'I want spam' checkbox, the 'email address' field becomes required.
Suggested solution: Add a 'condition' option to the "required" validator.
This condition can be set to a function (which returns true when the value is required).
Change History
comment:2 Changed 3 years ago by karel
Bummer. Disabling the control doesn't disable validation.
Changed this in rev 1430: Disabled controls are no longer validated.
comment:4 Changed 3 years ago by freya
- Owner changed from mpo to freya
- Status changed from new to assigned
comment:6 Changed 3 years ago by freya
'+validators': {
'isEmail': {
'isEnabled': function(){
check some other fields and return a boolean to enable/disable
return true;
}
},
'required': {}
}
Note: See
TracTickets for help on using
tickets.
Actually, come to think of it, this 'condition' operator can be applied to all validators.
In the given example I can just disable the "email address" field if the checkbox is checked (Although this is not always an option).
Perhaps it would be nice if you could enable/disable specific validations? Example of how it would be used:
mySpamControl.valueChanged(function() {
});