Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

angular - Bootstrap typescript display Required error for dropdown

I want to throw an error message when the user doesn't select an option and instead just keep the 1st option (which is the placeholder).

How can I throw an error when the default value is selected ?

My workings so far is displayed below and it doesn't show the expected result.

<select class="custom-select"  id="nm" required="required" [(ngModel)]="person.id" name="person-Id"
    #person="ngModel" [ngClass]="{ 'is-invalid': person.invalid && (person.dirty || person.touched || newForm.submitted), 'is-valid': person.valid && (person.dirty || person.touched || newForm.submitted) }">

    <option [ngValue]="0" disabled selected hidden>Select name</option>
    <option [ngValue]="1">xxx</option>
    <option [ngValue]="2">ttt</option>
</select>
<span class="text-danger" *ngIf="person.invalid && (person.dirty || person.touched || newForm.submitted) && person.errors?.required">select name</span>
question from:https://stackoverflow.com/questions/65910521/bootstrap-typescript-display-required-error-for-dropdown

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...