Brad
Brad

Reputation: 272

Radio buttons stop displaying their value when a radio button is selected in another object within the array

We have a section of our website where users can submit data. This section allows users to add additional entries and submit them all at once. We had to rewrite this section after we updated the version of AngularJS the site used to the most recent. When a user first accesses the page, the first entry is ready and available for the user to fill out. They can click on a button and it will add another entry. These entries can be navigated via tabs. Once a second entry has been added and a radio button selected, the selected radio button on the first entry is deselected in the view. If you go back to the first entry and re-select a radio button, any selected radio button on the second entry is de-selected. Checking the model, the values are still stored and if the user saves, then the correct values are saved to the database. I don't know if it matters in this case, but the radio button options are populated via data from the database. Everything in the controller appears to be working correctly.

Here is a concentrated bit from the template:

<uib-tabset active="activeTabIndex" ng-show="!nothingToShow && showThisStuff">
    <uib-tab ng-repeat="entry in things.items" active="{{entry.active}}" ng-model="entry">
        <uib-tab-heading>Heading Here</uib-tab-heading>
        <div>
            <!-- some other stuff here -->
            <div>
                <label>Label Here</label>
                <br />
                <div ng-repeat="input in inputTypes">
                    <input name="inputTypes" type="radio" data-ng-value="input.theTypeId" ng-model="entry.theTypeId">
                    <label>{{input.localizedName | translate}}</label>
                </div>
            </div>
            <!-- More stuff here-->
        </div>
    </uib-tab>
</uib-tabset>

I have a feeling that I'm not doing something right since ng-repeat is involved, but I feel that since the selection points to entry that multiple entries should be isolated from each other. Very well could be wrong, though.

Here's a list of things I've looked at to try and resolve this issue:

Upvotes: 0

Views: 547

Answers (1)

amir.algazi
amir.algazi

Reputation: 189

If I understand you correctly, you try to set multiple selection instead of single selection, do you?

Try one of the following: either remove the 'name' attribute from the input, or use $index in order to give every input its unique name (example: name="inputTypes_{{$index}}").

Upvotes: 0

Related Questions