As shown in the title, there is a form in which a p is controlled by a check box. If checked, the input element under the p will be displayed, and verification is required. If not checked, there is no need to verify hidden elements when the form is submitted. In the case of ng-if, even if validator="[required]" is added to the displayed elements, they will not be verified after being displayed. In the case of ng-hide, validator="[required]" will also perform required verification on the hidden elements.
Supplement: If you write the required attribute directly in the input tag, it seems that the desired effect can only be achieved under IE.
PHP中文网2017-05-15 17:10:25
I have never used ang_js, but I suggest that the author directly wraps an if judgment outside the section that verifies the hidden field input in the method it uses to verify the form. This should be able to achieve the minimum modification requirements without affecting the overall performance. Verification style, hope it helps you
PHP中文网2017-05-15 17:10:25
I always use ng-if, no problem. form submission.
<form name="myForm" novalidate>
<p ng-class="{'error': myForm.name.$invalid}" ng-if="show">
<input type="text" name="name" required>
</p>
</form>
Anything written in the controller should be returned when the form verification fails.