选择选项选择为0值时,使表单无效

时间:2018-04-06 10:23:59

标签: angular

<select name="tenure" 
        formControlName="tenure" 
        class="form-control" 
        (change)="TenureChange($event.target.value)">
     <option value="0">--select--</option>
     <option *ngFor="let tenur of ddltenure">{{tenur}}</option>
</select>
<span class="validation-block" 
       *ngIf="!planmodeForm.get('tenure').valid && planmodeForm.get('tenure').touched">
              Please select tenure
</span>

在我的组件中

this.planmodeForm = new FormGroup({
        'planmode': new FormControl(null, [Validators.required, Validators.pattern(this.planmodePattern)]),
        'tenure': new FormControl(null, Validators.required),
        'maxstudents': new FormControl(null, Validators.required),
        'maxusers': new FormControl(null, Validators.required),
        'notificationconf': new FormArray([])
    });

当slect选项更改为0

时,我想使表单无效

1 个答案:

答案 0 :(得分:2)

value="0"应为value="" required验证。