-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Document ngModel.$setValidity breaking change in the Changelog #8357
Comments
Yeah I think you are right and to be honest if we are decoupling validation from parsing the validators should not be modifying the value but there is much more to it than that. |
It seems the breaking change happened with the v1.3.0-beta.12. |
+1 to not modify the value |
@matsko are you on this? |
May be this is the logic that's causing trouble. #8080 (comment). |
Just to clarify, this is not a breaking change in $setValidity: So it's working more consistently now than before, but I don't think $modelValue should be set to undefined when validation fails. That's what $valid is for. |
…ogic The previous logic for async validation in `ngModelController` and `formController` was not maintainable: - control logic is in multiple parts, e.g. `ctrl.$setValidity` waits for end of promises and continuous the control flow for async validation - logic for updating the flags `ctrl.$error`, `ctrl.$pending`, `ctrl.$valid` is super complicated, especially in `formController` This refactoring makes the following changes: - simplify async validation: centralize control logic into one method in `ngModelController`: * remove counters `invalidCount` and `pendingCount` * use a flag `currentValidationRunId` to separate async validator runs from each other * use `$q.all` to determine when all async validators are done - centralize way how `ctrl.$modelValue` and `ctrl.$invalidModelValue` is updated - simplify `ngModelController/formCtrl.$setValidity` and merge `$$setPending/$$clearControlValidity/$$clearValidity/$$clearPending` into one method, that is used by `ngModelController` AND `formController` * remove diff calculation, always calculate the correct state anew, only cache the css classes that have been set to not trigger too many css animations. * remove fields from `ctrl.$error` that are valid and add `ctrl.$success`: allows to correctly separate states for valid, invalid, skipped and pending, especially transitively across parent forms. - fix bug in `ngModelController`: * only read out `input.validity.badInput`, but not `input.validity.typeMismatch`, to determine parser error: We still want our `email` validator to run event when the model is validated. - fix bugs in tests that were found as the logic is now consistent between `ngModelController` and `formController` BREAKING CHANGE: - `ctrl.$error` does no more contain entries for validators that were successful. Instead, they are now saved in `ctrl.$success`. - `ctrl.$setValidity` now differentiates between `true`, `false`, `undefined` and `null`, instead of previously only truthy vs falsy.
Talked with @IgorMinar and decided that the current handling is actually correct: Always set the model value to
|
I don't think you have understood why people complained about this. They Am 09.09.2014 21:41, schrieb Tobias Bosch:
|
@tbosch Another thing is that
is a weak argument, especially because noone has yet been confused about the different behaviors of parsers and validators except in this specific case where the new behavior differed from what they expected. Another thing is that especially in such a complex directive we should try to minimize side-effects of APIs. When people use $setValidity they will reasonably expect that it doesn't lead to the $modelValue becoming undefined, especially since that doesn't happen immediately, but only after you change the input. That's what people won't understand and complain about. Not changing this codifies confusing API behavior. |
@Narretz Sorry, yes, you are right that I understood it wrong what was the breaking change here. Ok, to not make it a breaking change, we would have to ignore errors for which there is not validator, right? |
@Narretz Would you like to take a step on creating a docs change for this? |
Mmh, rethinking this a little bit: Right now, calling How about this: whenever the validation runs, we clear all previous except for the newly detected ones. Then we would not have a breaking change in the sense of this issue. |
Hm, I don't think we have to make it so complicated. I also think it's okay to have a breaking change here, as long as the use case is supported, which is basically: have a property on the ngModelController that always reflects the return value of parsers. That is basically $$invalidModelValue (that's why imo it didn't make much sense to remove it without setting $modelValue to parser result) |
Calling `ctrl.$setValidity()` with a an error key that does not belong to a validator in `ctrl.$validator` should not result in setting the model to `undefined` on the next input change. This bug was introduced in 1.3.0-beta.12. Closes angular#8357 Fixes angular#8080
How about this: Via that external validators that call See the PR #9016 which is actually a very simple change. |
At some point in the 1.3.x branch ngModel.$modelValues were set as undefined when invalid. I couldn't find this change documented in the changelog, but it did break validation in our case.
1.2.x behavior: http://codepen.io/ItsLeeOwen/pen/EfwKC
1.3.x behavior: http://codepen.io/ItsLeeOwen/pen/CwALx
The text was updated successfully, but these errors were encountered: