-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Inconsistent handling of invalid initial ngModel values #8949
Comments
You won't be able to fix a number of these that you're claiming to be "not good" (otherwise we'd have inconsistencies between user specified values and model-specified values) |
I admit, I haven't looked into it. Do you mean because of native validators? |
You can't set a date or number input's values to something which doesn't fit the date or number parsing rules (I'm pretty sure that's the end result of what we do in setViewValue) http://jsfiddle.net/egedyh1v/ |
Ah, I see what you mean. However, I think I can improve the handling a little bit. |
Well, yeah I see what you mean. I think the code needs some comments why we're doing this. |
This is related to #9218 We should consider just throwing an error when we detect incorrect type rather than calling |
Yes, we should throw if the model has an invalid type. This would do the following:
@Narretz Does this sound good to you? |
I'm not really a fan of throwing in these cases. Just to be clear, the reason is that we don't want the formatting process to change the model? Otherwise we could at least try to "parse" the model. Or is the parsing part what makes this hard? |
Ok, talked again with @IgorMinar and we came up with this:
|
…e/…]` Similar to `input[number]` Angular will throw if the model value for a `input[date]` is not a `Date` object. For `Invalid Date`s (dates who’s `getTime()` is `NaN`) `input[date]` will render an empty string. Closes angular#8949
…e/…]` Similar to `input[number]` Angular will throw if the model value for a `input[date]` is not a `Date` object. For `Invalid Date`s (dates whose `getTime()` is `NaN`) `input[date]` will render an empty string. Closes angular#8949 Closes angular#9375
…e/…]` Similar to `input[number]` Angular will throw if the model value for a `input[date]` is not a `Date` object. For `Invalid Date`s (dates whose `getTime()` is `NaN`) `input[date]` will render an empty string. Closes angular#8949 Closes angular#9375
…e/…]` Similar to `input[number]` Angular will throw if the model value for a `input[date]` is not a `Date` object. For `Invalid Date`s (dates whose `getTime()` is `NaN`) `input[date]` will render an empty string. Closes angular#8949 Closes angular#9375
👏 |
woops... In my case I assume the user is responsible of his data and allow him to save invalid values. We were able (angular 1.2) to show him what's wrong each time he open the form. Well I'm not sure how to reproduce previous behavior. |
What is "show him what's wrong each time he open the form" supposed to mean? Please elaborate. |
Here is the case, the "form" is a meta query, this query cannot be executed until the parameters are not valid (a date or number depend of the parameter's type). So yes, the server must give incorrect values as it has been saved and yes I want to use native input type date/number. I'm surprised that angular assume the provided values must be correct. May be there is a UX mistake in my design, but I should not be the only one. |
Although I still have problems understanding exactly what you are doing, it seems like ngModelOptions.allowInvalid should solve your problems. You should provide an example of what you're doing if this is not the case. ----- Ursprüngliche Nachricht ----- Here is the case, the "form" is a meta query, this query cannot be executed until the parameters are not valid (a date or number depend of the parameter's type). |
An ngModelController created with an invalid inital value from scope behaves differently depending on input type:
http://jsfiddle.net/PK3QH/27/
I think we should always try to set the $viewValue to something. This is important if you have server-side data that may be invalid.
So number and date should not discard invalid values. If we pass garbage to the validators, the correct errors will be set.
Regarding calling toString on text-based input. I think that's okay as you will rarely set an object to a model when you know it'll be displayed in an input. But we should do "the right thing" and try to format values that are good enough, so in short:
I'll think I'll be able to throw a PR together over the weekend.
The text was updated successfully, but these errors were encountered: