angular 9 ui have a dropdown state and city defualt value state id=-1 and city=-1 ,on buton click ngform validation verify f.valid and city ='-1' then display erors and stateid='-1' display erors
[ngClass]="{'is-valid': f.submitted && cityID!=='-1', 'is-invalid' : f.submitted && reportingRangeTypeID=='-1'}"
(ngSubmit)="f.form.valid ? ButtonClick() :
(!cityID.valid && showErrorAlert('Password is required', 'Please enter a valid password'))">
[ngClass]="{'is-valid': f.submitted && cityID==='-1', 'is-invalid' : f.submitted && !city=='-1'}"
">
onbuton click form is true even cityid is -1.
Tuhin PaulPosted Apr 27, 2023, 6:31 PM
Try updating the ngClass directive for cityID
This should show the invalid class when the value of cityID is -1, and the valid class otherwise.
Tuhin PaulPosted Apr 27, 2023, 6:29 PM
There is a typing error in the ngClass directive for the cityID dropdown. Instead of checking if cityID==='-1', it checks if cityID'===-1'. The former checks if the value of the dropdown is a string '-1', while the latter checks if it is a number -1.