Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required input immediately marked invalid in Firefox with Ember 2.10 #14737

Closed
galfert opened this issue Dec 19, 2016 · 9 comments
Closed

Required input immediately marked invalid in Firefox with Ember 2.10 #14737

galfert opened this issue Dec 19, 2016 · 9 comments

Comments

@galfert
Copy link

galfert commented Dec 19, 2016

There seems to be a regression in Ember 2.10.0 in regards to required input fields.

In Firefox an input field {{input value=foo required=true}} is immediately marked as invalid (showing a red border around the field).

This is not the case in Ember 2.9.0, where the field is only marked as invalid when trying to submit the form with the field being empty.

I created an Ember Twiddle to reproduce it.

@galfert galfert changed the title Required input immediately marked invalid in Firefox Required input immediately marked invalid in Firefox with Ember 2.10 Dec 19, 2016
@galfert
Copy link
Author

galfert commented Jan 17, 2017

I'm willing to help fix this issue. Any pointers on where I should focus my search for the reason of this bug?

@ghost
Copy link

ghost commented May 26, 2017

Note that FireFox's implementation on the value + required attribute is actually correct.

https://www.w3.org/TR/html5/forms.html#dom-input-value-value

On setting, it must set the element's value to the new value, set the element's dirty value flag to true, invoke the value sanitization algorithm

@raucao
Copy link

raucao commented May 26, 2017

Should be possible to fix in Glimmer, if it's a regression:

This is not the case in Ember 2.9.0, where the field is only marked as invalid when trying to submit the form with the field being empty.

@martndemus Is validation the same as sanitization there? Dirty value would just mean it changed, whereas the validation should only kick in when either asking for it via the DOM API, or submitting the form afaik.

@galfert
Copy link
Author

galfert commented May 26, 2017

This is just a hunch, but could it be that Glimmer first inserts the input into the DOM and only then sets the value to the bound property? That might trigger Firefox's validation.

@rwjblue
Copy link
Member

rwjblue commented Dec 8, 2018

Hmm, this is surprising actually. Can someone double check if the same thing happens with plain JS?

let el = document.createElement('input');
el.setAttribute('type', 'input');
el.setAttribute('required', 'true');
el.setAttribute('value', '');
document.body.appendChild(el);

Does this have the same issue?

@galfert
Copy link
Author

galfert commented Dec 14, 2018

Does this have the same issue?

No, the input element produced with that snippet doesn't have the same issue.

@rwjblue
Copy link
Member

rwjblue commented Dec 21, 2018

OK, so the following is what we are doing internally today:

let el = document.createElement('input');
el.value = '';
el.setAttribute('required', '');
document.body.appendChild(el);

This shows the same issues as the twiddle.

However, the following does work properly:

let el = document.createElement('input');
el.setAttribute('value', '');
el.setAttribute('required', '');
document.body.appendChild(el);

@rwjblue
Copy link
Member

rwjblue commented Dec 21, 2018

AFAICT the only fix for this would be to move to using attributes first, but that requires broader changes (see emberjs/rfcs#314).

@locks locks added the wontfix label May 30, 2019
@locks
Copy link
Contributor

locks commented May 30, 2019

As mentioned by @rwjblue, fixing this has bigger implications that should be addressed by the linked to RFC. That is why I am marking this as wontfix and closing the issue.
Thanks for the discussion everyone! Go comment on the RFC 😁

@locks locks closed this as completed May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants