You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Add option to write invalid $modelValues to scope #8290
Since the validation refactoring, theoretically all invalid models appear in the input even if invalid. It's however not possible to write an invalid $modelValue to the scope. The $validators now actively set $modelValue to undefined when it is invalid, meaning that users cannot use the previous workarounds for this behavior. They now only have $$invalidModelValue to get the raw value, but that is undocumented and quasi-private. Additionally, with $validators, it is not possible anymore to use a $parser to set the model even if invalid (another common workaround)
I propose we use ng-model-options to make it possible to write the parsed $modelValue to scope even if invalid.
Displaying invalid models (from DB etc.): It currently displays the invalid model in the input, but at the same time resets the model to undefined (see http://plnkr.co/edit/Fapn7ePUhajjGNsjwIlg?p=preview)
just happened, I'm validating stuff server side, and when the user resubmit the form, it's gone, then the input becomes marked with required (since no data was sent to the server), even if I reset the validity state
I'm using required, minlength and "name" (custom validation state).
I set name manually using $setValidity from the server.
The field becomes $error = {required: false, minlength:false, name: true}
On model update on $watch, I reset name to false
$modelValue is now undefined on form submission
Server returns required: true, name: true, becomes an "endless client-server" loop
@petebacondarwin I don't know whether the change in behavior has anything to do with validators, I suspect a change to ngModel.$setValidity because in this comparison between 1.2.x - 1.3.x I'm not using $validators, and only end up with undefined $modelValues in the 1.3.x branch.
Activity
shahata commentedon Jul 22, 2014
I'll take a stab at this
leefernandes commentedon Jul 23, 2014
+1
logic using invalidated $modelValues is broken: http://codepen.io/ItsLeeOwen/pen/BcjDI
pocesar commentedon Jul 25, 2014
just happened, I'm validating stuff server side, and when the user resubmit the form, it's gone, then the input becomes marked with required (since no data was sent to the server), even if I reset the validity state
namemanually using$setValidityfrom the server.$error = {required: false, minlength:false, name: true}nameto false$modelValueis now undefined on form submissionrequired: true, name: true, becomes an "endless client-server" loopleefernandes commentedon Jul 26, 2014
Why can't or won't angular 1.3.x return to the days when invalid $modelValues were not undefined?
http://codepen.io/ItsLeeOwen/pen/DuJhg
petebacondarwin commentedon Jul 26, 2014
@itsleeowen - this was never the case with builtin validators: http://codepen.io/anon/pen/jykGi
leefernandes commentedon Jul 26, 2014
@petebacondarwin I don't know whether the change in behavior has anything to do with validators, I suspect a change to ngModel.$setValidity because in this comparison between 1.2.x - 1.3.x I'm not using $validators, and only end up with undefined $modelValues in the 1.3.x branch.
1.2.21: http://codepen.io/ItsLeeOwen/pen/EfwKC
1.3.x http://codepen.io/ItsLeeOwen/pen/CwALx
feat(ngModelOptions): add allowInvalid option
feat(ngModelOptions): add allowInvalid option
feat(ngModelOptions): add allowInvalid option
feat(ngModelOptions): add allowInvalid option
feat(ngModelOptions): add allowInvalid option
feat(ngModelOptions): add allowInvalid option