This repository has been archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
added min and max validation [Fixes #90] #91
Open
gruberb
wants to merge
2
commits into
ericelliott:master
Choose a base branch
from
gruberb:added_min_max_validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ | |
// User needs help. Enable active validation. | ||
$element.addClass(options.settings.activeClass); | ||
|
||
if ($errorID.length) { // These ifs are technically not needed, but improve server-side performance | ||
if ($errorID.length) { // These ifs are technically not needed, but improve server-side performance | ||
if ($element.attr('title')) { | ||
$errorID.text($element.attr('title')); | ||
} | ||
|
@@ -154,10 +154,12 @@ | |
rangeOverflow: validity.rangeOverflow || false, | ||
rangeUnderflow: validity.rangeUnderflow || false, | ||
stepMismatch: validity.stepMismatch || false, | ||
tooLong: validity.tooLong || false, | ||
rangeOverflow: validity.rangeOverflow || false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. We need this one. tooLong refers to the character length, not the number range. |
||
rangeUnderflow: validity.rangeUnderflow || false, | ||
tooHigh: validity.tooHigh || false, | ||
typeMismatch: validity.typeMismatch || false, | ||
valid: validity.valid || true, | ||
valueMissing: validity.valueMissing || false | ||
valueMissing: validity.valueMissing || false, | ||
valid: validity.valid || true | ||
}, validity); | ||
}, | ||
|
||
|
@@ -253,13 +255,15 @@ | |
errorIDbare = $this.attr(settings.errorAttribute) || false, // Get the ID of the error element. | ||
errorID = errorIDbare ? '#' + errorIDbare.replace(/(:|\.|\[|\])/g,'\\$1') : false, // Add the hash for convenience. This is done in two steps to avoid two attribute lookups. | ||
required = false, | ||
maxlength, | ||
min, | ||
max, | ||
validity = createValidity({element: this, valid: true}), | ||
$checkRequired = $('<input required>'), | ||
maxlength; | ||
$checkRequired = $('<input required>'); | ||
|
||
/* If the required attribute exists, set it required to true, unless it's set 'false'. | ||
* This is a minor deviation from the spec, but it seems some browsers have falsey | ||
* required values if the attribute is empty (should be true). The more conformant | ||
* This is a minor deviation from the spec, but it seems some browsers have falsey | ||
* required values if the attribute is empty (should be true). The more conformant | ||
* version of this failed sanity checking in the browser environment. | ||
* This plugin is meant to be practical, not ideologically married to the spec. | ||
*/ | ||
|
@@ -277,10 +281,22 @@ | |
|
||
maxlength = parseInt($this.attr('maxlength'), 10); | ||
if (!isNaN(maxlength) && value.length > maxlength) { | ||
validity.valid = false; | ||
validity.valid = false; | ||
validity.tooLong = true; | ||
} | ||
|
||
min = parseInt($this.attr('min'), 10); | ||
if(!isNaN(min) && (value < min)) { | ||
validity.valid = false; | ||
validity.rangeUnderflow = true; | ||
} | ||
|
||
max = parseInt($this.attr('max'), 10); | ||
if(!isNaN(max) && (value > max)) { | ||
validity.valid = false; | ||
validity.rangeOverflow = true; | ||
} | ||
|
||
if (required && !value) { | ||
validity.valid = false; | ||
validity.valueMissing = true; | ||
|
@@ -333,9 +349,9 @@ | |
/** | ||
* Take the event preferences and delegate the events to selected | ||
* objects. | ||
* | ||
* | ||
* @param {object} eventFlags The object containing event flags. | ||
* | ||
* | ||
* @returns {element} The passed element (for method chaining). | ||
*/ | ||
delegateEvents: function (selectors, eventFlags, element, settings) { | ||
|
@@ -359,10 +375,10 @@ | |
}, | ||
/** | ||
* Prepare for event delegation. | ||
* | ||
* | ||
* @param {object} settings The full plugin state, including | ||
* options. | ||
* | ||
* options. | ||
* | ||
* @returns {object} jQuery object for chaining. | ||
*/ | ||
bindDelegation: function (settings) { | ||
|
@@ -384,7 +400,7 @@ | |
$forms | ||
.attr('novalidate', 'novalidate') | ||
.submit(checkValidityOnSubmitHandler); | ||
|
||
$forms.find("input[formnovalidate][type='submit']").click(function(){ | ||
$(this).closest("form").unbind('submit', checkValidityOnSubmitHandler); | ||
}); | ||
|
@@ -418,9 +434,9 @@ | |
* - prevents submission if any invalid fields are found. | ||
* - Optionally validates all fields. | ||
* - Optionally moves focus to the first invalid field. | ||
* | ||
* @param {object} evt The jQuery Event object as from the submit event. | ||
* | ||
* | ||
* @param {object} evt The jQuery Event object as from the submit event. | ||
* | ||
* @returns {object} undefined if no validation was done, true if validation passed, false if validation didn't. | ||
*/ | ||
checkValidityOnSubmitHandler = function(evt) { | ||
|
@@ -486,10 +502,10 @@ | |
* expressions, and add them to the patternLibrary. Patterns in | ||
* the library are automatically assigned to HTML element pattern | ||
* attributes for validation. | ||
* | ||
* | ||
* @param {Object} patterns A map of pattern names and HTML5 compatible | ||
* regular expressions. | ||
* | ||
* | ||
* @returns {Object} patternLibrary The modified pattern library | ||
*/ | ||
addPatterns: function (patterns) { | ||
|
@@ -506,10 +522,10 @@ | |
* Take a valid jQuery selector, and a list of valid values to | ||
* validate against. | ||
* If the user input isn't in the list, validation fails. | ||
* | ||
* | ||
* @param {String} selector Any valid jQuery selector. | ||
* | ||
* @param {Array} values A list of valid values to validate selected | ||
* @param {Array} values A list of valid values to validate selected | ||
* fields against. | ||
*/ | ||
validValues: function (selector, values) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were already here. Now we have duplicates. );