根据第一个输入框为空或非空来切换强制。用户可以输入一个值并清除该值。检查输入框是否为空且需要切换
- 如果非空 - >其他控制都需要
- 如果空 - >其他控制都不需要
只要用户在第一输入框中输入的值,所需的控件应该用红色边框突出显示。如果用户清除该值或输入框为空,则不应显示这些红色边框。
找到这个PLUNKER
如果你能做到这一点只角特性将是巨大的。
HTML
<div ng-controller="TimeController as vm">
<form name="vm.timeForm" novalidate>
<div class="form-group">
<label>If you enter any value here below two fields becomes mandatory,
If I am empty below fields are not mandatory. </label>
<input type="number" name="firstfield" class="form-control"
ng-model="vm.firstfield" required>
</div>
<div class="form-group">
<label>Please select</label>
<select class="form-control" ng-model="vm.selectedOption" ng-change="vm.updateMinMax()" ng-required="vm.firstfield">
<option value="hours">HOURS</option>
<option value="minutes">MINUTES</option>
<option value="seconds">SECONDS</option>
</select>
</div>
<div class="form-group" ng-class="{ 'has-error' : vm.timeForm.desiredRPO.$invalid && !vm.timeForm.desiredRPO.$pristine }">
<label>Desired Time</label>
<input type="number" name="desiredRPO" class="form-control" ng-model="vm.desiredRPO" ng-min="vm.minValue" ng-max="vm.maxValue" ng-required="vm.firstfield">
<p ng-show="vm.timeForm.desiredRPO.$invalid" class="help-block">Please enter value between {{vm.minValue}} and {{vm.maxValue}}</p>
</div>
</form>
</div>
嘿,你能解决问题? – AlexP