angular.js - If the form submission does not require required verification when the hidden element is not displayed, what should I do if it needs to be verified when it is displayed?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:08:25
0
5
824

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.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(5)
左手右手慢动作

It would be great if you write js directly for verification,

洪涛

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

淡淡烟草味

ng-required

洪涛

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.

刘奇

The hidden form is set to non-required

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template