Reputation: 13086
I create a simple form with a textbox and a dropdown. Both are required.
When I click submit button textbox becomes red while dropdown doesn't change.
Here the plunkr: https://embed.plnkr.co/oSe3JCMlB4jBNsjOgUoc/
I want both fields becames red when user click the submit button.
What I miss?
Upvotes: 2
Views: 1026
Reputation: 3353
I believe this is because the required
Validator checks to see if the FormControl
is touched
.
You can do this manually as described in this question
submit(form) {
this.form.get('test2').markAsTouched()
console.log(form)
}
It is also better to use (ngSubmit)
instead of a click event on the submit button.
Upvotes: 1
Reputation:
You have
'test1': new FormControl("", Validators.required)
in your code (select-form-example.ts) which is telling angular that it is a required field, hence the red box for failed validation. Try
'test1': new FormControl("")
Upvotes: 0