Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Allow attributes to have a value of zero (eg min='0') #1029

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Contributor

nicjansma commented Mar 5, 2014

I've found that HTML rule attributes that have a value of 0 are not applied, for example, min="0". If min="0" is specified, the user could still enter -1 in the <input> field.

This is because in attributeRules() there is a truthy test on the attribute's value before the rule is applied, so anything equal to 0 will be ignored.

To fix this, we also check for value === 0. If so, the rule is applied.

Tests were added to validate this.

@nschonni nschonni and 1 other commented on an outdated diff Mar 5, 2014

src/core.js
@@ -910,6 +910,9 @@ $.extend($.validator, {
if ( value ) {
rules[method] = value;
+ } else if ( typeof value === "number" && value === 0 ) {
@nschonni

nschonni Mar 5, 2014

Collaborator

This could be combined with the previous conditional

if ( value || value === 0) )

the typeof can probably be skipped since you are using a strict comparison

@nicjansma

nicjansma Mar 5, 2014

Contributor

Good point, PR updated

Contributor

nicjansma commented Mar 12, 2014

Any other feedback? Pretty simple PR with unit test coverage of the changes.

Collaborator

jzaefferer commented Mar 12, 2014

Thanks! Landed with an updated commit message to close another PR and separate ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment