Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
7
<select class=form-control  formControlName=accessName id=val-skill name=val-skill>
<option value=>Please select</option>
<option [value]=admin>Admin</option>
<option [value]=staff>Staff</option>
</select>

[#5674] Wednesday, November 6, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsleyashlynnh

Total Points: 64
Total Questions: 119
Total Answers: 98

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
kinsleyashlynnh questions
Tue, Sep 7, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Fri, Jul 19, 19, 00:00, 5 Years ago
;