#NgForm is showing valid even though required fields are not selected
8 messages · Page 1 of 1 (latest)
Where does it show valid? We also need to see how you constructed the form in the ts file. Maybe you just need to add [disalbed] to the button?```html
<button mat-raised-button color="primary" type="submit" [disabled]="ngForm.invalid">
<mat-icon>search</mat-icon>
</button>
at the very bottom of the form is my submit button. that button calls this method in my ts:
if (form.valid) {
console.log('Form is valid');
} else {
console.log('Form is invalid');
}
...
}
Is there any other code you need to see?
Please show how form is declared.
the form is only declared in my html (first line of the HTML that I attached), it is not declared in my ts.
Oh you're using template driven forms. I'm not familiar with them. Do all the required fields validate or only the ones in the arrays?
Also is it possible that it is allowing an empty string?
when leaving all fields empty, the form is (correctly) invalid: