У меня есть два поля ввода, и оба поля обязательны для заполнения на стороне сервера, но я хочу заполнить любое из двух полей ввода, другое может быть нулем.
HTML-файл:
<div class="form-group">
<label class="control-label col-sm-4" for="minFreeTerminals">Min Free Terminals:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="minFreeTerminals" maxlength="4" title="Enter Free terminals for the Exam" placeholder="Min Free Terminals" formControlName="minFreeTerminals" ng-model="User.minFreeTerminals" [ngClass]="{ 'is-invalid': submitted && f.minFreeTerminals.errors }">
<div *ngIf="submitted && f.minFreeTerminals.errors" class="invalid-feedback">
<div *ngIf="f.minFreeTerminals.errors.required" style="color:red;font-size: 12px;">Min Free Terminals is required</div>
<div *ngIf="f.minFreeTerminals.errors.pattern" style="color:red;font-size: 12px;">Only Numbers are Allowed</div>
</div>
<span class="md-line"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="minFreeTerminalPercentage">Min Free Terminal Percentage:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="minFreeTerminalPercentage" maxlength="5" title="Enter Free terminal Percentage for the Exam" placeholder="Min Free Terminal Percentage" formControlName="minFreeTerminalPercentage" ng-model="User.minFreeTerminalPercentage" [ngClass]="{ 'is-invalid': submitted && f.minFreeTerminalPercentage.errors }">
<div *ngIf="submitted && f.minFreeTerminalPercentage.errors" class="invalid-feedback">
<div *ngIf="f.minFreeTerminalPercentage.errors.required" style="color:red;font-size: 12px;">Min Free Terminal Percentage is required</div>
<div *ngIf="f.minFreeTerminalPercentage.errors.pattern" style="color:red;font-size: 12px;">Only Numbers are Allowed</div>
</div>
<span class="md-line"></span>
</div>
</div>
файл TS:
this.CreateExamFG = this._fb.group({
minFreeTerminals: ['', [Validators.required, Validators.pattern(this.OnlyNumbers)]],
minFreeTerminalPercentage: ['', [Validators.required, Validators.pattern(this.numericNumberReg)]]
}
)
}