Angular: Conditionally trigger selective form validations
I am using a reactive form with validations - 'required' and others like min, max, etc for the form fields. There are two buttons in the form - 'Save' and 'Submit'. Events on Save and Submit buttons will save data to intermediate state and submit it respectively according to the back end logic.
For Submit button, I have disabled it until the form is valid by property binding disabled attribute to form's invalid state. For Save button, I need to disable it if the fields are invalid according to the validations defined except 'required' validation. This is to check if any invalid inputs are entered.
For example, consider following form
this.registerForm = this.formBuilder.group({
name: [''],
email: ['', [Validators.required, Validators.email]],
})
In this case, I need to disable the button if invalid input is entered in the field, but enable it if it is left blank, that is ignore 'required' validation. The 'required' validation is required for disabling another button, that is Submit button.
How achieve such selective validations for different buttons?