diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2b94995ff..a4c233aa9 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -12,6 +12,7 @@ - **Sticky** - Fixed `sticky` element that cannot fit in viewport not scrolling correctly when fixed to viewport #2605 - **Form** - Fixed issue with `minLength[1]` validation not behaving same as `minLength > 2` #2636. - **Form** - Form fields will now error when a non-string identifier is used +- **Form** - Added `doesntContain` and `doesntContainExactly` # **Additional Bugs** - **Popup** - `wide` and `very wide` popup will now limit themselves to normal popup widths on mobile so that they still appear on screen. diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 8f84b1b91..970edc1bc 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -1069,6 +1069,64 @@ $.fn.form.settings = { return emailRegExp.test(value); }, + // value is most likely url + url: function(value) { + return $.fn.form.settings.regExp.url.test(value); + }, + + // matches specified regExp + regExp: function(value, regExp) { + var + regExpParts = regExp.match($.fn.form.settings.regExp.flags), + flags + ; + // regular expression specified as /baz/gi (flags) + if(regExpParts) { + regExp = (regExpParts.length >= 2) + ? regExpParts[1] + : regExp + ; + flags = (regExpParts.length >= 3) + ? regExpParts[2] + : '' + ; + } + return value.match( new RegExp(regExp, flags) ); + }, + + // is valid integer or matches range + integer: function(value, range) { + var + intRegExp = $.fn.form.settings.regExp.integer, + min, + max, + parts + ; + if(range === undefined || range === '' || range === '..') { + // do nothing + } + else if(range.indexOf('..') == -1) { + if(intRegExp.test(range)) { + min = max = range - 0; + } + } + else { + parts = range.split('..', 2); + if(intRegExp.test(parts[0])) { + min = parts[0] - 0; + } + if(intRegExp.test(parts[1])) { + max = parts[1] - 0; + } + } + return ( + intRegExp.test(value) && + (min === undefined || value >= min) && + (max === undefined || value <= max) + ); + }, + + // is value (case insensitive) is: function(value, text) { text = (typeof text == 'string') @@ -1087,6 +1145,24 @@ $.fn.form.settings = { return (value == text); }, + // value is not another value (case insensitive) + not: function(value, notValue) { + value = (typeof value == 'string') + ? value.toLowerCase() + : value + ; + notValue = (typeof notValue == 'string') + ? notValue.toLowerCase() + : notValue + ; + return (value != notValue); + }, + + // value is not another value (case sensitive) + notExactly: function(value, notValue) { + return (value != notValue); + }, + // value contains text (insensitive) contains: function(value, text) { // escape regex characters @@ -1115,67 +1191,32 @@ $.fn.form.settings = { return (value.search( new RegExp(text) ) === -1); }, - // value is not value (case insensitive) - not: function(value, notValue) { - value = (typeof value == 'string') - ? value.toLowerCase() - : value - ; - notValue = (typeof notValue == 'string') - ? notValue.toLowerCase() - : notValue + // is exactly length + length: function(value, requiredLength) { + return (value !== undefined) + ? (value.length == requiredLength) + : false ; - return (value != notValue); - }, - - // value is not value (case sensitive) - notExactly: function(value, notValue) { - return (value != notValue); }, - // is valid integer - integer: function(value, range) { - var - intRegExp = $.fn.form.settings.regExp.integer, - min, - max, - parts + // is at least string length + minLength: function(value, requiredLength) { + return (value !== undefined) + ? (value.length >= requiredLength) + : false ; - if(range === undefined || range === '' || range === '..') { - // do nothing - } - else if(range.indexOf('..') == -1) { - if(intRegExp.test(range)) { - min = max = range - 0; - } - } - else { - parts = range.split('..', 2); - if(intRegExp.test(parts[0])) { - min = parts[0] - 0; - } - if(intRegExp.test(parts[1])) { - max = parts[1] - 0; - } - } - return ( - intRegExp.test(value) && - (min === undefined || value >= min) && - (max === undefined || value <= max) - ); }, - // is at least string length - length: function(value, requiredLength) { + // is less than length + maxLength: function(value, maxLength) { return (value !== undefined) - ? (value.length >= requiredLength) + ? (value.length <= maxLength) : false ; }, // matches another field - different: function(value, identifier) { - // use either id or name of field + match: function(value, identifier) { var $form = $(this), matchingValue @@ -1193,13 +1234,13 @@ $.fn.form.settings = { matchingValue = $('[name="' + identifier +'[]"]'); } return (matchingValue !== undefined) - ? ( value.toString() !== matchingValue.toString() ) + ? ( value.toString() == matchingValue.toString() ) : false ; }, - // matches another field - match: function(value, identifier) { + // different than another field + different: function(value, identifier) { // use either id or name of field var $form = $(this), @@ -1218,7 +1259,7 @@ $.fn.form.settings = { matchingValue = $('[name="' + identifier +'[]"]'); } return (matchingValue !== undefined) - ? ( value.toString() == matchingValue.toString() ) + ? ( value.toString() !== matchingValue.toString() ) : false ; }, @@ -1251,38 +1292,6 @@ $.fn.form.settings = { return (value.search(',') === -1); } return (value.split(',').length <= maxCount); - }, - - regExp: function(value, regExp) { - var - regExpParts = regExp.match($.fn.form.settings.regExp.flags), - flags - ; - // regular expression specified as /baz/gi (flags) - if(regExpParts) { - regExp = (regExpParts.length >= 2) - ? regExpParts[1] - : regExp - ; - flags = (regExpParts.length >= 3) - ? regExpParts[2] - : '' - ; - } - return value.match( new RegExp(regExp, flags) ); - }, - - // string length is less than max length - maxLength: function(value, maxLength) { - return (value !== undefined) - ? (value.length <= maxLength) - : false - ; - }, - - // value is most likely url - url: function(value) { - return $.fn.form.settings.regExp.url.test(value); } }