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 }}
Repository navigation
Angular2 Forms Controls validation "OnLostFocus (OnBlur)" rather than "OnChange" #7113
Looking at the code for setting up form controls in shared.ts it appears we detect control changes onChange "registerOnChange"
eg. if a user types into an input control that is an ng2 angular control, each keypress triggers a validationcheck ..
It appears to be a big change if i were to change it from OnChange to something like LostFocus of the control ...
The reason i ask is business really doesn't like the validation messages appearing suddenly even while the user hasn't finished filling in the field ... eg. filling in a "Password" control, the user is suddenly shown validation errors while they're typing ...
Anyone got a nice solution for hiding validation messages and only showing them once they tab off the control ?!
Reacted by Christian Ulmann, Arthur Helmel, Groschenroman, Mateus Pinheiro, Milad, Anselm, Ali Houssein, Heather Stevens, derek, Alexei Pancratov and 66 more
That's interesting.
So the class valid/dirty/invalid seems nice (I guess you can agree with the decorator that say the field is not yet compliant).
However I agree that the messages are more cumbersome and sometimes obvious enough (like on a login screen)
The problem is when to display them then? how to know the user is "done"
For example I have a form that disables the submit button if the form is invalid. If it's the last field that is invalid, the user is editing it. He can't click on the button, so the "lost focus" event might not come depending on the user behaviour.
Let me throw a couple of UX ideas that use form validation on each change, but that react a bit differently (async ?) to it:
display the errors/details after some timer of inactivity (a bit heavy)
display the errors/details in a way that does not disturb the form layout (in a side floating tooltip rather than in a div that appear/disappear below each input)
I think the issue is just about being able to use the blur event instead of the change event for calling the validator, so validation is only done when the user is done editing a field.
display the errors/details in a way that does not disturb the form layout (in a side floating tooltip rather than in a div that appear/disappear below each input)
Shouldn't bee too hard. This is IMHO only a CSS problem not an Angular problem.
display the errors/details after some timer of inactivity (a bit heavy)
Shouldn't be too hard to implement. Just create an additional flag used in *ngIf to show/hide validation errors. Subscribe to form changes and if there is some delay toggle the flag.
thanks guys ... ill try out the recommendation from zoechi ...
our interaction designers are very adamant that the UI should NOT be changing whilst the user is entering data .. apparently they hate any form of distraction for the user during their data entry interaction..
Reacted by Heather Stevens, Tobias Punke, Yashwanth Harikrishnan, Noah Teshu, Justin Rassier, Mark Leppke, Abdel, deserwantus, Marko Samastur, verjik and 8 more
+1 to have the option to validate on blur vs on change. If blur, don't mark an input as dirty unless the value has changed and the user has moved focus out of the input.
The onBlur validation is definitely something I occasionally used in Angular 1, and will be implementing via a "controller" function if no provision is made by Angular 2. +1
changed the title [-]Angular2 Forms Controls validation "OnLostFocus" rather than "OnChange" [/-][+]Angular2 Forms Controls validation "OnLostFocus (OnBlur)" rather than "OnChange" [/+]on Jun 15, 2016
hi everyone !
i wanna know whether this validate-onblur mechanism has been implemented in @angular/forms 0.2.0 ? if not, is there any workaround to do this ?
@liquidboy If the concern is that the error messages are being displayed as the user types (too early), have you considered using the touched property? A control is only marked touched on the blur event, so the error message would not appear until then.
What we don't have yet is support for actually running the validation on blur instead of on value change. Besides error message display, what are some other use cases for this? Trying to get a read on priority.
Reacted by Ismail Hrimech, Kevin Pinto, Hans Van den Keybus, Emre Öztürk, Lucas Basquerotto, Alessandro Kreslin, Adithya N.J, Giuseppe Piscopo, Paul Bargaoanu, Aldo Román and 8 more
Thus because i been struggling with the sane issue here. maybe you can help. I am trying to validate a form using angular formBuilder..here is my code:
Validations firing onBlur appear to conflict with having a 'Cancel' button for the form. Cancel is not like a form reset, it is a 'total dismiss' of the input/edit operation, possibly even closing the form.
If a field has focus, then the validation logic fires when the field loses focus and before the Cancel click occurs. This is particularly a bad UX when the form is inside a modal - since the Cancel button also should dismiss the modal, except it cannot because of the validation firing first.
I believe in Angular 1.x we could set form.submitted = false inside the Cancel click handler, but in Angular 2+ submitted is a read-only attribute and cannot be set.
So how can we 'form cancel' without firing any validations?
this post should be awarded "most patient users ever"
Reacted by marokac, Dimi, James Krot, asdfasdfasdfasdf asd, Laszlo Lang, Daniel Macák, Imad El Hitti, Mark Wiemer, Jadurani Davalos and Pieter Van Der Helst
Activity
gbataille commentedon Feb 17, 2016
That's interesting.
So the class valid/dirty/invalid seems nice (I guess you can agree with the decorator that say the field is not yet compliant).
However I agree that the messages are more cumbersome and sometimes obvious enough (like on a login screen)
The problem is when to display them then? how to know the user is "done"
For example I have a form that disables the submit button if the form is invalid. If it's the last field that is invalid, the user is editing it. He can't click on the button, so the "lost focus" event might not come depending on the user behaviour.
Let me throw a couple of UX ideas that use form validation on each change, but that react a bit differently (async ?) to it:
what do you think?
zoechi commentedon Feb 17, 2016
I think the issue is just about being able to use the
blurevent instead of thechangeevent for calling the validator, so validation is only done when the user is done editing a field.Shouldn't bee too hard. This is IMHO only a CSS problem not an Angular problem.
Shouldn't be too hard to implement. Just create an additional flag used in
*ngIfto show/hide validation errors. Subscribe to form changes and if there is some delay toggle the flag.liquidboy commentedon Feb 17, 2016
thanks guys ... ill try out the recommendation from zoechi ...
our interaction designers are very adamant that the UI should NOT be changing whilst the user is entering data .. apparently they hate any form of distraction for the user during their data entry interaction..
ps2goat commentedon Mar 17, 2016
+1 to have the option to validate on blur vs on change. If blur, don't mark an input as dirty unless the value has changed and the user has moved focus out of the input.
JohnnyClutch commentedon May 24, 2016
The onBlur validation is definitely something I occasionally used in Angular 1, and will be implementing via a "controller" function if no provision is made by Angular 2. +1
[-]Angular2 Forms Controls validation "OnLostFocus" rather than "OnChange" [/-][+]Angular2 Forms Controls validation "OnLostFocus (OnBlur)" rather than "OnChange" [/+]bruceauyeung commentedon Jul 15, 2016
hi everyone !
i wanna know whether this
validate-onblurmechanism has been implemented in@angular/forms 0.2.0? if not, is there any workaround to do this ?BBegouin commentedon Jul 19, 2016
+1 :) any news of this feature ?
AliHoussein commentedon Aug 11, 2016
+1 interested as well!
Cuel commentedon Sep 28, 2016
Ran into this issue myself, would be nice if the form controls could report if their input is currently active/focused
kara commentedon Oct 13, 2016
@liquidboy If the concern is that the error messages are being displayed as the user types (too early), have you considered using the
touchedproperty? A control is only markedtouchedon the blur event, so the error message would not appear until then.What we don't have yet is support for actually running the validation on blur instead of on value change. Besides error message display, what are some other use cases for this? Trying to get a read on priority.
78 remaining items
marokac commentedon Oct 24, 2017
Thus because i been struggling with the sane issue here. maybe you can help. I am trying to validate a form using angular formBuilder..here is my code:
ngOnInit() {
this.formBuilder = new FormBuilder();
this.simpleForm = this.formBuilder.group({
notifyMeRadio: [],
notifyMeEmail: [this.notifyMeEmail,[CommonValidators.isValidEmailAddress]],
notifyMeSMS: [this.notifyMeSMS, [Validators.minLength(10)]],
notifyMeFax: [this.notifyMeFax,[CommonValidators.isValidBeneficiaryName]],
notifyBeneficiaryRadio: [''],
notifyBeneficiaryEmail: [this.notifyBeneficiaryEmail,[CommonValidators.isValidEmailAddress]],
notifyBeneficiarySMS: [this.notifyBeneficiarySMS,[Validators.minLength(10)]],
notifyBeneficiaryFax: [this.notifyBeneficiaryFax,[Validators.minLength(10)]],
});
this.simpleForm.valueChanges.subscribe(data => this.onValueChanged(data));
this.onValueChanged();
And my validation messages object goes like this:
validationMessages = {
'notifyMeSMS': {'required':'field cannot be empty',
'isValidEmailAddress':'10 digist'
},
'notifyMeEmail': {'required': 'Please enter valid Email address'},
'notifyMeFax' : { 'required': 'Please enter valid Fax name',
'isValidBeneficiaryName':'isValidBeneficiaryName'
},
SMS', 'isValidEmailAddress':'please type a valid email address'},
'notifyBeneficiaryEmail': {'required':'required field'},
'notifyBeneficiaryFax' : {'required':'Please enter valid beneficiary Fax'},
};
Form errors here:
formErrors: {
'notifyMeRadio':'',
'notifyMeEmail': '',
'notifyMeSMS': '',
'notifyMeFax': ''
},
And finally my OnvalueChange method:
onValueChanged(data?: any) {
if (!this.simpleForm) { return; }
const form = this.simpleForm;
}
My issue here is i can only get validation messages when i include required and it only return required only
please help guys
marokac commentedon Oct 24, 2017
@notsonotso I will beg you on this one my man please help if you can...
trotyl commentedon Oct 24, 2017
@marokac GitHub issue is not used for support request, please refer to CONTRIBUTING for more information.
marokac commentedon Oct 24, 2017
Point taken brah ..thanks any way
rmcsharry commentedon Feb 1, 2018
Validations firing onBlur appear to conflict with having a 'Cancel' button for the form. Cancel is not like a form reset, it is a 'total dismiss' of the input/edit operation, possibly even closing the form.
If a field has focus, then the validation logic fires when the field loses focus and before the Cancel click occurs. This is particularly a bad UX when the form is inside a modal - since the Cancel button also should dismiss the modal, except it cannot because of the validation firing first.
SO example here.
I believe in Angular 1.x we could set form.submitted = false inside the Cancel click handler, but in Angular 2+ submitted is a read-only attribute and cannot be set.
So how can we 'form cancel' without firing any validations?
steelx commentedon Apr 19, 2018
this post should be awarded "most patient users ever"
marokac commentedon Apr 19, 2018
Thank you
jkrot commentedon Apr 24, 2018
I would still like this as well because doing silly things with render to get this to happen doesn't make me happy.
imadhy commentedon Jul 4, 2018
updates ?
spyro2000 commentedon Jul 16, 2018
Why isn't that just a global setting or something?
SystemDisc commentedon Aug 31, 2018
Someone come up with a solid proposal that we can agree on. Then, a PR can be made implementing that proposed solution.
marokac commentedon Aug 31, 2018
I think we can fire the blur event only when click happens inside the form
angular-automatic-lock-bot commentedon Sep 14, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.