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
Validate form on submission in reactive-form FormGroup #14527
I'm submitting a
[ ] bug report
[x] feature request
[ ] support request
Current behavior
Current version of FormGroup, validation happens on value changes to which form will be subscribed.
eg:- this.myForm.valueChanges.subscribe(data => this.onValueChanged(data));
And submit button will be disabled by default. Which works fine and good in a way.
But i also need to be able to enable the submit button by default.
Expected behavior
Instead of validating form on value change, can we have one more option of validating form on submission of form?
eg:- this.myForm.formSubmit.subscribe(data => this.onFormSubmit(data));
What is the motivation / use case for changing the behavior?
Client requirement to validate form on submit than on value change like old ways.
Button is disabled by default. Also form is getting validated on input changes.
Instead my requirement is submit button should be enabled by default, when user clicks on submit form should then validate and display appropriate error message if any.
I guess disabled button should be the expected behaviour while form is invalid. BTW if you need your application to act on submit instead of doing asynchronous checks for validation and all, you can make simple template driven form for your use case.
Is that what you're looking for, or is there a specific reason you'd like to wait to run validation? With how forms are set up now, the form status is kept up to date whenever the value changes, but you have complete control over when and how the UI changes to reflect the new status.
Reacted by Theophilus Omoregbee, luisalbertonavarro, Bedini Fabio aka whisher , Alex, Piotr Jankowski, Marcel Német, Jhonatan Acevedo Martínez, Akhil Antony K, Scott Harsla, Manis Takaur and 6 more
Activity
DzmitryShylovich commentedon Feb 16, 2017
can you add a plunkr?
preetham1290 commentedon Feb 16, 2017
Here is the plunker link
https://plnkr.co/edit/2lTTIWxO1acUxsJHDkje?p=preview
Button is disabled by default. Also form is getting validated on input changes.
Instead my requirement is submit button should be enabled by default, when user clicks on submit form should then validate and display appropriate error message if any.
ritikrishu commentedon Feb 16, 2017
@preetham1290
you plunker is not running on my system for some reason, but I see you have written some thing like:
I guess disabled button should be the expected behaviour while form is invalid. BTW if you need your application to act on submit instead of doing asynchronous checks for validation and all, you can make simple template driven form for your use case.
kara commentedon Feb 17, 2017
@preetham1290 If I'm understanding correctly, you want your submit button to be enabled until submission, then disabled if the form fails to validate?
You can actually achieve this already with the
submittedflag on the top level form directive.Validation will still occur on value change, but the errors and the button disabling will not appear until the submit event.
I updated your plunker with an example: https://plnkr.co/edit/V45rysvHGfgc8sBig1Ds?p=preview
Is that what you're looking for, or is there a specific reason you'd like to wait to run validation? With how forms are set up now, the form status is kept up to date whenever the value changes, but you have complete control over when and how the UI changes to reflect the new status.
kara commentedon Aug 12, 2017
@preetham1290 We added a feature in 5.0.0-beta.3 to allow applications to delay validation until submit. See the PR here.
laxmikanta415 commentedon Oct 24, 2017
Reseting the form in simple javascript is the solution for now.
angular-automatic-lock-bot commentedon Sep 13, 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.