Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(jqLite): Firefox validation trigger #12106

Closed
wants to merge 1 commit into from

Conversation

lgalfaso
Copy link
Contributor

Do not trigger Firefox validation on form initialization.

  • Do not set a value to an field if the field already has the same value

Closes #12102

@@ -671,7 +671,10 @@ forEach({
}
return element.value;
}
element.value = value;
// Workaround for Firefox validation #12102.
if (element.value != value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the != intentional ? It can lead to bugs in corner cases.
E.g. when value === '' and one calls elem.val(0), they would expect elem.val() === '0', but since 0 == '', nothing will happen (I think).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element.value is always a string. If the value we are going to set it to will be transformed to the same string, then do not copy the value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but value can be anything the user passes (e.g. 0).
If element.value === '' and value === 0, I would expect the element's value to be set to '0', but because '' != 0 evaluates to false, the element's value will remain '', right ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules for transforming to string are not the same as the rules for != comparison.
Maybe you should compare element.value to String(value) or something ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...although that is not accurate for value === null, because String(null) === 'null', but element.value = null ==> element.value === '', so that need to be taken into account as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just be on the safe side and do !==

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, does it solve the initial Firefox issue :) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It solves it as long as the initial value of ngModel is not the same as the input[value] (in most cases we expect that input[value] to be an empty string, so yes, just doing !== should be fine... famous last words)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, since https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1128 takes care of the empty values (null, undefined), it should be fine :)
So, using !== sounds like the simplest (aka best) way out...

@gkalpak
Copy link
Member

gkalpak commented Jun 15, 2015

If we decide that we want this change, would it be possible to make the change in a "higher" level (i.e. somewhere in ngModel), so that it will work the same as jQuery (or would it be too messy) ?

@lgalfaso
Copy link
Contributor Author

Do not trigger Firefox validation on form initialization.
- Do not set a value to an <input> field if the field already has the same value

Closes angular#12102
@lgalfaso
Copy link
Contributor Author

landed as e742316

@lgalfaso lgalfaso closed this Jul 26, 2015
lgalfaso added a commit to lgalfaso/angular.js that referenced this pull request Aug 15, 2015
Add a test that checks that an <input> value is not set when the value is equal
to the current value
petebacondarwin pushed a commit that referenced this pull request Jan 20, 2016
Add a test that checks that an <input> value is not set when the value is equal
to the current value

Closes #12592
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Jan 20, 2016
Add a test that checks that an <input> value is not set when the value is equal
to the current value

Closes angular#12592
petebacondarwin pushed a commit that referenced this pull request Jan 21, 2016
Add a test that checks that an <input> value is not set when the value is equal
to the current value

Closes #12592
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants