From a690601b3fd8b63867771ab5aae31d18b306a31f Mon Sep 17 00:00:00 2001 From: jlukic Date: Mon, 23 Feb 2015 15:08:25 -0500 Subject: [PATCH] Adds #1858, case sensitive/insensitive form validation rules --- RELEASE-NOTES.md | 8 +++- src/definitions/behaviors/form.js | 42 +++++++++++++++++-- src/definitions/collections/form.less | 4 +- src/themes/default/collections/form.variables | 6 +-- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1fb7ca4e2..1f751c1f9 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,12 +2,16 @@ ### Version 1.9.4 - February 21, 2015 +**Changes** +- **Form Validation** - Adds `containsExactly`, `notExactly`, `isExactly` case sensitive validation rules, make `contains`, `not`, `is` case insensitive. +- **Form Validation** - `contains` rule is now case insensitive +- **Form Validation** - Validation messages no longer increase field height on `inline fields` like checkboxes after error appears - **Build Tools** - Fixed issue with recursive merge for site themes in update scripts, [details here](https://github.com/Semantic-Org/Semantic-UI/pull/1845) Thanks @derekslife - **API** - Added `was cancelled` to determine whether request was cancelled by `beforeSend` - **State** - Text states now handle `cancelled` API requests correctly -- **Search** - Category search no longer displays unnecessary error message about setting maxResults +- **Search** - Category search no longer displays unnecessary error message about maxResults - **Composer** - Composer.json should now read version from tags, adjusted some fields. -- **Grid** - Stackable grid now has horizontal padding on mobile unless inside a `ui grid` or `ui segment` +- **Grid** - Stackable grid now has horizontal padding by default on mobile unless nested inside a `ui grid` or `ui segment` (not vertical) - **Menu** - Fixes pointing menu displaying under dropdown menu ### Version 1.9.3 - February 20, 2015 diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 06fdfca3c..81d05bcc3 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -969,10 +969,18 @@ $.fn.form.settings = { return ($(this).filter(':checked').length > 0); }, - // value contains (text) + // value contains text (insensitive) contains: function(value, text) { + // escape regex characters text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - return (value.search(text) !== -1); + return (value.search( new RegExp(text, 'i') ) !== -1); + }, + + // value contains text (case sensitive) + containsExactly: function(value, text) { + // escape regex characters + text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + return (value.search( new RegExp(text) ) !== -1); }, // is most likely an email @@ -1020,8 +1028,21 @@ $.fn.form.settings = { ); }, - // is exactly value + // is value (case insensitive) is: function(value, text) { + text = (typeof text == 'string') + ? text.toLowerCase() + : text + ; + value = (typeof value == 'string') + ? value.toLowerCase() + : value + ; + return (value == text); + }, + + // is value + isExactly: function(value, text) { return (value == text); }, @@ -1063,8 +1084,21 @@ $.fn.form.settings = { ; }, - // value is not exactly notValue + // value is not 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 value (case sensitive) + notExactly: function(value, notValue) { return (value != notValue); }, diff --git a/src/definitions/collections/form.less b/src/definitions/collections/form.less index 316dc24ed..65930aab5 100755 --- a/src/definitions/collections/form.less +++ b/src/definitions/collections/form.less @@ -240,10 +240,10 @@ white-space: nowrap; } .ui.form .inline.field .prompt { - margin: @validationMargin; + margin: @inlineValidationMargin; } .ui.form .inline.field .prompt:before { - margin-top: @validationArrowOffset; + margin-top: @inlineValidationArrowOffset; bottom: auto; right: auto; top: 50%; diff --git a/src/themes/default/collections/form.variables b/src/themes/default/collections/form.variables index 795c46ba7..924126b70 100644 --- a/src/themes/default/collections/form.variables +++ b/src/themes/default/collections/form.variables @@ -73,9 +73,9 @@ /* Divider */ @dividerMargin: @rowDistance 0em; -/* Validation Prompt */ -@validationMargin: 0em 0em 0em @rowDistance; -@validationArrowOffset: -0.3em; +/* Inline Validation Prompt */ +@inlineValidationMargin: -0.5em 0em -0.5em @rowDistance; +@inlineValidationArrowOffset: -0.3em; /*------------------- States