Commit 60c899e7 authored by Peter Droogmans's avatar Peter Droogmans
Browse files

Issue #2180281 by mmtt: Text field with Multiple Options.

parent f9142abb
...@@ -707,17 +707,34 @@ ...@@ -707,17 +707,34 @@
jQuery.each (self.forms[formid].checkboxrules, function(r) { jQuery.each (self.forms[formid].checkboxrules, function(r) {
var $checkboxes = $form.find(this.checkboxgroupminmax[2]).find('input[type="checkbox"]'); var $checkboxes = $form.find(this.checkboxgroupminmax[2]).find('input[type="checkbox"]');
if ($checkboxes.length) { if ($checkboxes.length) {
$checkboxes.addClass('require-one'); var identifier = 'require-one-' + this.checkboxgroupminmax[2].substring(1);
var min = this.checkboxgroupminmax[0];
var message = this.messages.checkboxgroupminmax;
$checkboxes.addClass(identifier);
$checkboxes.each(function(){ $checkboxes.each(function(){
var $checkbox = $(this);
var rule = self.forms[formid].checkboxrules[r]; var rule = self.forms[formid].checkboxrules[r];
if (typeof self.validators[formid].settings.messages[r] === 'undefined') { var newrule = {
self.validators[formid].settings.messages[r] = {}; require_from_group: [min, '.' + identifier]
} }
$.extend(self.validators[formid].settings.messages[r], rule.messages); $checkbox.rules("add", newrule);
delete rule.messages; $checkbox.change(hideErrordiv);
$(this).rules("add", rule);
$(this).change(hideErrordiv); if (typeof self.validators[formid].settings.messages[$checkbox.attr('name')] === 'undefined') {
self.validators[formid].settings.messages[$checkbox.attr('name')] = {};
}
$.extend(self.validators[formid].settings.messages[$checkbox.attr('name')], {
require_from_group: message
});
}); });
if (typeof self.validators[formid].settings.messages['.' + identifier] === 'undefined') {
self.validators[formid].settings.messages['.' + identifier] = {};
}
$.extend(self.validators[formid].settings.messages['.' + identifier], {
require_from_group: message
});
console.log(self.validators[formid].settings.messages);
} }
}); });
self.time.stop('checkboxrules'); self.time.stop('checkboxrules');
...@@ -1335,6 +1352,28 @@ ...@@ -1335,6 +1352,28 @@
} }
}, jQuery.format('Not a valid EAN number.')); }, jQuery.format('Not a valid EAN number.'));
jQuery.validator.addMethod("require_from_group", function(value, element, options) {
var $fields = $(options[1], element.form),
$fieldsFirst = $fields.eq(0),
validator = $fieldsFirst.data("valid_req_grp") ? $fieldsFirst.data("valid_req_grp") : $.extend({}, this),
isValid = $fields.filter(function() {
return validator.elementValue(this);
}).length >= options[0];
// Store the cloned validator for future validation
$fieldsFirst.data("valid_req_grp", validator);
// If element isn't being validated, run each require_from_group field's validation rules
if (!$(element).data("being_validated")) {
$fields.data("being_validated", true);
$fields.each(function() {
validator.element(this);
});
$fields.data("being_validated", false);
}
return isValid;
}, jQuery.validator.format("Please fill at least {0} of these fields."));
/** /**
* Allow other modules to add more rules. * Allow other modules to add more rules.
* @event clientsideValidationAddCustomRules * @event clientsideValidationAddCustomRules
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment