Link the radio buttons in two different fields with Angular

advertisements

need some help on radio buttons. How can i bind 2 radio buttons that are for one particular question but use 2 different fields in the database. For example there is a question that has a Yes/No answer. The yes answer binds to one field, and the No answer to another, they don't bind to a single filed that has a true, false value.

         <div class="radio-s">
            <input type="radio" ng-value="true" data-name="use_plan"
                   data-value="true" ng-model="record.offer_plan" />
            <label>Yes</label>
        </div>
        <div class="radio-s">
            <input type="radio" ng-value="false" data-name="use_plan"
                   data-value="true" ng-model="record.offer_plan" />
    <label>No</label>
        </div>

Thanks in advance.


Attach the name attribute to both of your radio buttons so that only one can be selected at a time and also bind them to the respective fields from your DB

        <div class="radio-s">
            <input type="radio" name="planGroup" ng-value="true" data-name="use_plan"
                   data-value="true" ng-model="record.offer_plan_yes" />
            <label>Yes</label>
        </div>
        <div class="radio-s">
            <input type="radio" name="planGroup" ng-value="false" data-name="use_plan"
                   data-value="true" ng-model="record.offer_plan_no" />
        <label>No</label>
        </div>