0

my code looks like this:

 <ng-form name="form">

    <div>
        Question 1
        <label>
            <input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
                   ng-value="false">
               No
        </label>

        <label>
            <input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1||q2||q3)">
                Yes
        </label>

    </div>

    <div  ng-show="!q1">
        Question 2 
        <br/>
        <label>
            <input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
                   ng-value="false">
            No            </label>
        <br/>
        <label>
            <input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1|| q2|| q3)">
                Yes            </label>
        <br/>
    </div>

    <div ng-show="!q1 && !q2">
       Question 3
        <br/>
        <label>
            <input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
                   ng-value="false">
                No
        </label>
        <br/>
        <label>
            <input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
                   ng-value="true" ng-required="!(q1|| q2|| q3)">
                Yes
        </label>
        <br/>

    </div>

    </ng-form>

So, I need one (and only one) "Yes" answer for questions. However, $form.invalid is always false. I see that 'required="required"' is successfully added to input fields when it should be added, so ng-required condition works ok ;).

http://jsfiddle.net/ahL58/134/

1 Answer 1

1

Give names to radio inputs by group. Otherwise form will can not check validation

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... but i'm still not sure how can I do this. I added jsfiddle. Any ideas? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.