43
rated 0 times
[
47]
[
4]
/ answers: 1 / hits: 7841
/ 5 Years ago, fri, november 8, 2019, 12:00:00
I want to set up validation for my dropdown.
Here is my template code...
<div class=form-group row>
<label class=col-lg-4 col-form-label for=val-skill>Designation <span class=text-danger>*</span>
</label>
<div class=col-lg-6>
<select class=form-controlid=val-skill name=val-skill>
<option value=>Please select</option>
<option value=admin>Admin</option>
<option value=staff>Staff</option>
</select>
</div>
<div *ngIf=accessName.touched && accessName.invalid>
<div *ngIf=accessName.errors.required>
<div class=alert alert-danger>
Select access type
</div>
</div>
</div>
</div>
and this is my form control code...
form = new FormGroup({
accessName:new FormControl('',Validators.required),
});
get accessName() {
return this.form.get(accessName);
}
Dropdown is selected to 'Please select' by default. When the user touched the drop down and not changed the type it should display the validation error.
How can I do this implementation?
More From » angular