My app is built using Angular 8
. It features a form where users can input movie details and ticket information.
Data Model Setup:
export class Movie
{
name:string;
}
export class Ticket
{
name:string;
price:number;
}
To create the form, I am utilizing Reactive Form as shown below.
public buildForm(): FormGroup {
return this.form = this.fb.group({
/* movie */
'name': ['', [Validators.required, Validators.minLength(3)]],
/* tickets*/
'tickets': this.fb.array([this.buildTicketForm()])
})
}
public buildTicketForm(): FormGroup {
return this.fb.group({
'name': ['',[Validators.required, Validators.minLength(3)]],
'price': [0.00,[Validators.required, Validators.min(0.00)]],
})
}
Now, my specific requirement is to have ticket validations triggered conditionally.
The ticket validations should apply only if there is a ticket name; otherwise, no need to validate.
Thank you!