Skip to content

Commit

Permalink
#2636 Tests & Fixes 0, 1, and 2 conditions for minLength, maxLength a…
Browse files Browse the repository at this point in the history
…nd exactLength
  • Loading branch information
jlukic committed Jul 14, 2015
1 parent 5f0d07c commit 93a92d2
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,11 @@ $.fn.form = function(parameters) {
ancillary,
functionType
;
// cast to string
value = $.trim($field.val() + '');

// cast to string avoiding encoding special values
value = (value === undefined || value === '' || value === null)
? ''
: $.trim(value + '')
;
// if bracket notation is used, pass in extra parameters
if(bracket) {
ancillary = '' + bracket[1];
Expand Down Expand Up @@ -1185,19 +1187,34 @@ $.fn.form.settings = {
;
},

maxCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length <= count);
exactCount: function(value, exactCount) {
if(exactCount == 0) {
return (value === '');
}
if(exactCount == 1) {
return (value !== '' && value.search(',') === -1);
}
return (value.split(',').length == exactCount);
},

exactCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length == count);
minCount: function(value, minCount) {
if(minCount == 0) {
return true;
}
if(minCount == 1) {
return (value !== '');
}
return (value.split(',').length >= minCount);
},

minCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length >= count);
maxCount: function(value, maxCount) {
if(maxCount == 0) {
return false;
}
if(maxCount == 1) {
return (value.search(',') === -1);
}
return (value.split(',').length <= maxCount);
},

regExp: function(value, regExp) {
Expand Down

0 comments on commit 93a92d2

Please sign in to comment.