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

allowInvalid doesn't work with input[number] #11390

Closed
asedim opened this issue Mar 21, 2015 · 2 comments
Closed

allowInvalid doesn't work with input[number] #11390

asedim opened this issue Mar 21, 2015 · 2 comments

Comments

@asedim
Copy link

asedim commented Mar 21, 2015

I need to temporarily store form input whether it is valid or not. I wanted to just store whole form model but the invalid fields were giving me some problems. I found that adding ng-model-options="{ allowInvalid: true }" should solve it. And it did for fields like input[email] or input[url], but not for the input[number].
http://jsfiddle.net/19kyru7k/

I would expect value in the last input to be printed whether or not it is valid if option allowInvalid is used. Should I consider this as a bug? Because if feels like it.

Tested using Angular 1.3.14 and 1.4.0-beta.6 in Chrome.

@gkalpak
Copy link
Member

gkalpak commented Mar 22, 2015

I believe it has to do with how browsers handle number inputs (in regard ith their number contraint).
When you enter an invalid email into an input[type="email"], the field is marked as invalid, inp.value returns the (invalid) string you have entered. When you enter an invalid number (e.g. www) into an input[type="number"], the field is marked an invalid, but inp.value does not return the (invalid) value.

So, I don't think there is any way for Angular to determine what is the invalid value entered into a number field, in order to assign it to the model.

Note, that allowInvalid: true works as expected on number fields as far as other validation constraints are concerned (e.g. min/max etc).

@Narretz
Copy link
Contributor

Narretz commented Mar 22, 2015

Yeah, that's unfortunately how it works. Best we can do is add a note to the docs.

@Narretz Narretz added this to the Backlog milestone Mar 22, 2015
@Narretz Narretz self-assigned this Jun 6, 2015
@Narretz Narretz closed this as completed in a25aa5b Jun 6, 2015
netman92 pushed a commit to netman92/angular.js that referenced this issue Aug 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants