0

I've got an Angular Material Reactive Form in my example with some simple inputs and validations. I've built in two buttons: one outside, one inside the form tag. Can anyone tell me why the whole form gets validated if clicked on the button inside the form?

How can I block the validation in this case?

Example: https://stackblitz.com/edit/angular-ivy-m4kar5?file=src%2Fapp%2Fhello.component.html

2 Answers 2

3

Because the default button attribute type is "submit", so you need to set button type to button to achieve your requirement.

<button type="button">Click me and watch everything gets validated</button>
Sign up to request clarification or add additional context in comments.

Comments

1

The button inside the form, has by default the property type="submit". If you have more than one button inside a form tag, you must specify the type :

<form>
  <button>Submit the form</button> <!-- Default is submit -->

  <button type="button">Some random action</button>

  <button type="reset">Reset a form</button>
</form>

1 Comment

Thanks, your answer is right too, but the other guy was faster and had a source. But I appreciate your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.