Sitelet https://web.archive.org/web/20211003072632/https://github.com/angular/angular.js/issues/16916
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng-options with "track by" in select box makes all clicked options "selected" #16916

Open
1 of 4 tasks
mjmlopes opened this issue Nov 18, 2019 · 1 comment
Open
1 of 4 tasks

Comments

@mjmlopes
Copy link

@mjmlopes mjmlopes commented Nov 18, 2019

I'm submitting a ...

  • regression from 1.7.0
  • security issue
  • issue caused by a new browser version
  • other

Current behavior:
By visiting this page https://code.angularjs.org/1.7.8/docs/api/ng/directive/select, section "Using select with ngOptions and setting a default value", all of "Make a choice" options which are clicked on will have the selected="selected" parameter set:
<select name="mySelect" id="mySelect" ng-options="option.name for option in data.availableOptions track by option.id" ng-model="data.selectedOption" class="ng-valid ng-not-empty ng-touched ng-dirty ng-valid-parse"><option label="Option A" value="1" selected="selected">Option A</option><option label="Option B" value="2" selected="selected">Option B</option><option label="Option C" value="3" selected="selected">Option C</option></select>

Expected / new behavior:
Instead of
<option label="Option C" value="3" selected="selected">Option C</option>
could be selected only:
<option label="Option C" value="3" selected>Option C</option>
, and only for the current option which is selected, removing the parameter for the other not selected options.

Minimal reproduction of the problem with instructions:
By visiting this page https://code.angularjs.org/1.7.8/docs/api/ng/directive/select, section "Using select with ngOptions and setting a default value" and the default option is "Option C". When clicking on other options, to the respective option tags will be added the parameter selected="selected".

AngularJS version:
1.7.8

Browser:
Chrome 78.0.3904.97 (64 bit)
Firefox 68.2.0esr (64-bit)
(both running in Debian 9)

@Narretz
Copy link
Contributor

@Narretz Narretz commented Feb 24, 2020

While this isn't ideal, multiple selected attributes don't actually interfere with the functionality of the select, e.g. the right option should still be selected and in the model. Ofc it's possible that accessibility tools use the selected attribute, and it makes writing tests that check for selected more problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants