jQuery UI Widgets › Forums › Plugins › Validator, Drag & Drop, Sortable › calling function in validator ???
Tagged: Angular validator, default, function, jquery validator, jqxvalidator, predefined, rule, validator
This topic contains 3 replies, has 3 voices, and was last updated by Dimitar 9 years ago.
-
Author
-
Hi
is there a way that i can convert following code into a function and can call the same functionality in multiple forms for validation purpose rather than duplicating every where ..?
$(‘#searchForm’).jqxValidator({
closeOnClick: true,
rules: [
{
input: ‘#comboBoxBrand input’, message: ‘Select Brand’, action: ‘keyup’, position: ‘right:20,0’, rule: function (input, commit) {
var value = $(‘#comboBoxBrand’).val();
if (value == ” || value == null) {
return false;
}
return true;
}
},
{
input: ‘#comboBoxGroup input’, message: ‘Select Group’, action: ‘keyup’, position: ‘right:20,0’, rule: function (input, commit) {
var brand = $(“#comboBoxBrand”).jqxComboBox(‘getSelectedItem’);
var value = $(‘#comboBoxGroup’).val();
if (brand && (value == ” || value == null)) {
return false;
}
return true;
}
},
{
input: ‘#comboBoxSubGroup input’, message: ‘Select Sub-Group’, action: ‘keyup’, position: ‘right:20,0’, rule: function (input, commit) {
var brand = $(“#comboBoxBrand”).jqxComboBox(‘getSelectedItem’);
var group = $(“#comboBoxGroup”).jqxComboBox(‘getSelectedItem’);
var value = $(‘#comboBoxSubGroup’).val();
if (brand && group && (value == ” || value == null)) {
return false;
}
return true;
}
}
]
});Thanks
Hello mallepaddi,
You can assign a function to the rule, i.e.:
var ruleFunction = function (input, commit) { //...};
…
{ input: '#comboBoxBrand input', message: 'Select Brand', action: 'keyup', position: 'right:20,0', rule: ruleFunction}
However, your three rule functions are rather different and I do not see how they can be conveniently combined into one.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Is it possible to call a predefined rule such as email once a custom function has been used.
Hello JasonHans,
You can apply both predefined and custom rules to a single input. This can be seen in the demo Default Functionality (for the passwordConfirmInput field).
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.