For my current project on Ionic 4, I have implemented a form builder to create and validate forms. I have also included the [disabled]
attribute in the form to disable it if all fields are not valid.
However, I noticed that even if I do not add Validators.required
to a field, it still considers it as a required field. Here is an example of my code:
.ts file
createAddAtelierDressForm() {
this.addAtelierDressForm = this.fb.group({
title: ['', Validators.required],
description: ['', Validators.required],
type: ['', Validators.required],
size: ['', Validators.required],
category: ['', Validators.required],
city: ['', Validators.required],
action: ['', Validators.required],
price: ['', Validators.required],
discount: ['', Validators.required],
image_1: ['', Validators.required],
image_2: [''],
image_3: [''],
});
}
In the above code snippet, you can see that image_2
and image_3
do not have the required validation condition.
HTML
<form [formGroup]="addAtelierDressForm">
<!-- Input fields for different form elements -->
<!-- Submit button with disabled attribute based on form validity -->
<ion-button expand="full" type="submit" [disabled]="!addAtelierDressForm.valid">Add Dress</ion-button>
</form>
The issue I am facing is that the form remains disabled even after filling all fields, including image_2
and image_3
.