-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngModel): fix issues when parserName is same as validator key #10850
Conversation
For $validate(), it is necessary to store the parseError state in the controller. Otherwise, if the parser name equals a validator key, $validate() will assume a parse error occured if the validator is invalid. Also, setting the validity for the parser now happens after setting validity for the validator key. Otherwise, the parse key is set, and then immediately afterwards the validator key is unset (because parse errors remove all other validations). Fixes angular#10698 Closes angular#10850
bd1795e
to
5d62a95
Compare
@@ -518,7 +519,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |||
|
|||
// Check if the there's a parse error, so we don't unset it accidentially | |||
var parserName = ctrl.$$parserName || 'parse'; |
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.
This variable doesn't seem to be used now. What does this mean for the default of 'parse'?
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 see that the errorKey
variable sets the default below on line 563
I updated the test. I removed the variables that handle the validity of parser / validators. Instead, they now directly react to the input. If you're okay with the test, can we merge this, and push the parseName refactor back? The bug is pretty gnarly and we can fix the parser name later. |
@@ -1221,6 +1221,96 @@ describe('ngModel', function() { | |||
expect(ctrl.$validators.mock).toHaveBeenCalledWith('a', 'ab'); | |||
expect(ctrl.$validators.mock.calls.length).toEqual(2); | |||
}); | |||
|
|||
iit('should validate correctly when $parser name equals $validator key', function() { |
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.
iit
For $validate(), it is necessary to store the parseError state in the controller. Otherwise, if the parser name equals a validator key, $validate() will assume a parse error occured if the validator is invalid. Also, setting the validity for the parser now happens after setting validity for the validator key. Otherwise, the parse key is set, and then immediately afterwards the validator key is unset (because parse errors remove all other validations). Fixes angular#10698 Closes angular#10850
For $validate(), it is necessary to store the parseError state in the controller. Otherwise, if the parser name equals a validator key, $validate() will assume a parse error occured if the validator is invalid. Also, setting the validity for the parser now happens after setting validity for the validator key. Otherwise, the parse key is set, and then immediately afterwards the validator key is unset (because parse errors remove all other validations). Fixes #10698 Closes #10850 Closes #11046
Oh! Sorry @Narretz - when I squashed I attributed it to me instead of you. I am sorry about that - I will not do it again. Great work. |
For $validate(), it is necessary to store the parseError state in the controller. Otherwise, if the parser name equals a validator key, $validate() will assume a parse error occured if the validator is invalid. Also, setting the validity for the parser now happens after setting validity for the validator key. Otherwise, the parse key is set, and then immediately afterwards the validator key is unset (because parse errors remove all other validations). Fixes angular#10698 Closes angular#10850 Closes angular#11046
For $validate(), it is necessary to store the parseError state
in the controller. Otherwise, if the parser name equals a validator
key, $validate() will assume a parse error occured if the validator
is invalid.
Also, setting the validity for the parser now happens after setting
validity for the validator key. Otherwise, the parse key is set,
and then immediately afterwards the validator key is unset
(because parse errors remove all other validations).
Fixes #10698
Closes #10828