-
Notifications
You must be signed in to change notification settings - Fork 27.3k
refactor(ngModelController,formController): #8941
Conversation
src/ng/directive/input.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be careful with making $setValidity private. There are many custom validation implementations that rely on this. With $validators, many have become obsolete, but there is at least one (that I can can think of now) that's not so easily emulated: when you $http the whole form to the server for validation, and then use $setValidity to apply the results (legacy apps). I don't think you can do that with $validators.
src/ng/directive/form.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the meaning of setUnset variable? it's a weird name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't follow the logic of the conditions in the following code. if it's supposed to really toggle the classes then I'd expect the conditions to be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the method to cachedToggleClass. It sets/removes the css class based on the given argument. The name is the same as the one in jQuery, although this method does not support to be called with no argument, see http://api.jquery.com/toggleclass/#toggleClass-className-switch
I don't know a better name for this :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to parameter to switchValue, just like in the jQuery method...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah. ok. now it makes sense. thanks
|
overall I like this change. it needs a bit more cleanup though. |
3dc38b7 to
cdbab90
Compare
|
Ok, just did. All tests are passing again, and I updated the commit message. |
cdbab90 to
09c8079
Compare
|
Ok, also rebased on top of master... |
|
@Narretz it could, although I have not explicitly checked. When I work on those other PRs, I will add their tests and see what happens. |
09c8079 to
4f4af0c
Compare
|
As far as I can see this PR fixes the issue addressed by those PR's |
|
👍 |
4a8e051 to
24e8115
Compare
…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 private `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.
- `ctrl.$setValidity` now differentiates between `true`, `false`,
`undefined` and `null`, instead of previously only truthy vs falsy.
24e8115 to
a3b3b68
Compare
…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 private `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.
- `ctrl.$setValidity` now differentiates between `true`, `false`,
`undefined` and `null`, instead of previously only truthy vs falsy.
Closes #8941
refactor(ngModelController,formController): centralize and simplify l…
…ogic
The previous logic for async validation in
ngModelControllerandformControllerwas not maintainable:ctrl.$setValiditywaits for end of promises and continuous the control flow
for async validation
ctrl.$error,ctrl.$pending,ctrl.$validis super complicated, especially in
formControllerThis refactoring makes the following changes:
into one method in
ngModelController:invalidCountandpendingCountcurrentValidationRunIdto separateasync validator runs from each other
$q.allto determine when all async validators are donectrl.$modelValueandctrl.$invalidModelValueis updated
ngModelController/formCtrl.$setValidityand merge$$setPending/$$clearControlValidity/$$clearValidity/$$clearPendinginto one method, that is used by
ngModelControllerANDformControlleronly cache the css classes that have been set to not
trigger too many css animations.
ctrl.$errorthat are valid and addctrl.$success:allows to correctly separate states for valid, invalid, skipped and pending,
especially transitively across parent forms.
ngModelController:input.validity.badInput, but notinput.validity.typeMismatch,to determine parser error: We still want our
emailvalidator to run event when the model is validated.
ngModelControllerandformController