ch.Condition
Description
Condition utility.
How-to
// Create a new condition object with patt.
var condition = ch.Condition({
'name': 'string',
'patt': /^([a-zA-Z\u00C0-\u00C4\u00C8-\u00CF\u00D2-\u00D6\u00D9-\u00DC\u00E0-\u00E4\u00E8-\u00EF\u00F2-\u00F6\u00E9-\u00FC\u00C7\u00E7\s]*)$/,
'message': 'Some message here!'
});
//Create a new condition object with expr.
var condition = ch.Condition({
'name': 'maxLength',
'patt': function(a,b) { return a.length <= b },
'message': 'Some message here!',
'value': 4
});
// Create a new condition object with func.
var condition = ch.Condition({
'name': 'custom',
'patt': function (value) {
if (value === 'ChicoUI') {
// Some code here!
return true;
};
return false;
},
'message': 'Your message here!'
});
Parameters
-
condition
- Array : A conditions to validate.-
name
- String : The name of the condition. -
message
- String : The given error message to the condition. -
fn
- String : The method to validate a given condition.
-
Properties
.Condition#name
String
The name of the component.
Methods
-
value
- String | Number : A given value. -
validation
- condition : A given validation to execute.
.constructor()
Returns a reference to the constructor function.
.disable() → {condition}
Disables an instance of a condition.
// Disabling an instance of Condition.
condition.disable();
// Disabling a condition.
condition.disable();
.enable() → {condition}
Enables an instance of condition.
// Enabling an instance of Condition.
condition.enable();
// Enabling a condition.
condition.enable();
.test(value, validation) → {Boolean}
Enables an instance of condition.
// Testing a condition.
condition.test('foobar', validationA);