jQuery EasyUI Form Plugin - Validatebox
jQuery EasyUI Plugins
Override the default defaults via $.fn.validatebox.defaults.
The validatebox is designed to validate form input fields. If the user enters an invalid value, it changes the background color, displays a warning icon, and shows a tooltip message. The validatebox can be integrated with the form plugin to prevent invalid fields from being submitted.
Depends on
- tooltip
Usage
Create a validatebox from markup.
Create a validatebox using JavaScript.
$('#vv').validatebox({
required: true,
validType: 'email'
});
Checks that the password and the re-entered password are the same.
// extend the 'equals' rule
$.extend($.fn.validatebox.defaults.rules, {
equals: {
validator: function(value,param){
return value == $(param[0]).val();
},
message: 'Field do not match.'
}
});
Validation Rules
Validation rules are defined using the required and validType properties; here are the rules already implemented:
- email: matches the email regular expression rule.
- url: matches the URL regular expression rule.
- length[0,100]: allows from x to y characters.
- remote['http://.../action.do','paramName']: sends an AJAX request to validate the value, returning 'true' on success.
To customize validation rules, override $.fn.validatebox.defaults.rules to define a validation function and an invalid message. For example, define a minLength validation type:
$.extend($.fn.validatebox.defaults.rules, {
minLength: {
validator: function(value, param){
return value.length >= param[0];
},
message: 'Please enter at least {0} characters.'
}
});
Now you can use this minLength validation type to define an input box that requires at least 5 characters:
property
| Name | Type | Description | Default value |
|---|---|---|---|
| required | boolean | Defines whether the field is required to be filled in. | false |
| validType | string,array | Defines the validation type of the field, such as email, url, and so on. Possible values: |
1、验证类型字符串,应用单个验证规则。
2、验证类型数组,应用多个验证规则。单个字段上的多个验证规则自版本 1.3.2 起可用。
代码实例:
| null| onSelect | event | delay | number | Delays validation of the last entered value. This property is available since version 1.3.2. | 200| onSelect | event | missingMessage | string | The tip text shown when the text box is empty. | This field is required.| onSelect | event | invalidMessage | string | The tip text shown when the content of the text box is invalid. | null| onSelect | event | tipPosition | string | Defines the position of the tip message when the text box content is invalid. Possible values: 'left', 'right'. This property is available since version 1.3.2. | right| onSelect | event | deltaX | number | The tip offset in the X direction. This property is available since version 1.3.3. | 0| onSelect | event | novalidate | boolean | When set to true, validation is disabled. This property is available since version 1.3.4. | false |
Method
| Name | Parameters | Description |
|---|---|---|
| destroy | none | Remove and destroy the component. |
| validate | none | Perform validation to determine whether the content of the text box is valid. |
| isValid | none | Call the validate method and return the validation result, true or false. |
| enableValidation | none | Enable validation. This method is available since version 1.3.4. |
| disableValidation | none | Disable validation. This method is available since version 1.3.4. |
jQuery EasyUI Plugins