Browse Source

#4267 #5253 Fix some mistaken logic

pull/5507/merge
Jack 7 years ago
parent
commit
8f1409aeb5
1 changed files with 19 additions and 9 deletions
  1. 28
      src/definitions/behaviors/form.js

28
src/definitions/behaviors/form.js

@ -663,14 +663,14 @@ $.fn.form = function(parameters) {
module.add.field(name, rules); module.add.field(name, rules);
}, },
field: function(name, rules) { field: function(name, rules) {
rules = $.isArray(rules)
? rules
: [rules]
;
var var
newValidation = {} newValidation = {}
; ;
if(module.is.shorthandRules(rules)) { if(module.is.shorthandRules(rules)) {
rules = $.isArray(rules)
? rules
: [rules]
;
newValidation[name] = { newValidation[name] = {
rules: [] rules: []
}; };
@ -679,9 +679,7 @@ $.fn.form = function(parameters) {
}); });
} }
else { else {
newValidation[name] = {
rules: rules
};
newValidation[name] = rules;
} }
validation = $.extend({}, validation, newValidation); validation = $.extend({}, validation, newValidation);
module.debug('Adding rules', newValidation, validation); module.debug('Adding rules', newValidation, validation);
@ -756,6 +754,11 @@ $.fn.form = function(parameters) {
? rule ? rule
: [rule] : [rule]
; ;
if(rule == undefined) {
module.debug('Removed all rules');
validation[field].rules = [];
return;
}
if(validation[field] == undefined || !$.isArray(validation[field].rules)) { if(validation[field] == undefined || !$.isArray(validation[field].rules)) {
return; return;
} }
@ -773,12 +776,19 @@ $.fn.form = function(parameters) {
: [field] : [field]
; ;
$.each(fields, function(index, field) { $.each(fields, function(index, field) {
delete validation[field];
module.remove.rule(field);
}); });
}, },
// alias // alias
rules: function(field, rules) { rules: function(field, rules) {
module.remove.rule(field, rules);
if($.isArray(field)) {
$.each(fields, function(index, field) {
module.remove.rule(field, rules);
});
}
else {
module.remove.rule(field, rules);
}
}, },
fields: function(fields) { fields: function(fields) {
module.remove.field(fields); module.remove.field(fields);

Loading…
Cancel
Save