I'm using ng-select
for dropdown search but I'm unable to get validation if not selecting anything from dropdown.
I return like bellow:
<div class="form-group">
<ng-select [items]="productData" [searchable]="true" bindLabel="productName"
[formControl]="prodCode"
[ngClass]="{ 'is-invalid': submitted && f.prodCode.errors }"
placeholder="Select Product" required>
</ng-select>
<div *ngIf="submitted && f.prodCode.errors" class="invalid-feedback">
<div *ngIf="f.prodCode.errors.required">Product Code is required</div>
</div>
</div>
in Ts File
this.productForm = this.fb.group({
prodCode: new FormControl(null, Validators.required)
});
get f() {
return this.productForm.controls;
}
this.submitted = true;
if (this.productForm.invalid) {
return;
}
So kindly requesting you please let me know where is my mistake....