Ticket #263 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

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:1 Changed 3 years ago by karel

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() {

if (this.getValue().valueOf() === true) {

myEmailControl.getValidator('required').enable();
myRequiredMarker.text("*");

} else {

myEmailControl.getValidator('required').disable();
myRequiredMarker.text("");

}

});

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:3 Changed 3 years ago by mpo

  • Milestone changed from 0.4 to 0.4.1

comment:4 Changed 3 years ago by freya

  • Owner changed from mpo to freya
  • Status changed from new to assigned

comment:5 Changed 3 years ago by freya

(In [1648]) * See #263 : conditional validator. you can add a 'isEnabled' method to a validator to sepcify whether or not to enable the validation.

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': {}

}

comment:7 Changed 3 years ago by freya

  • Status changed from assigned to closed
  • Resolution set to fixed

comment:8 Changed 3 years ago by jgou

  • Milestone changed from 0.4.1 to 0.4
Note: See TracTickets for help on using tickets.