ng-model bug: Options shifted by one after selecting the first time
See original GitHub issueIf you use the ng-model attribute, all the data-option-array-index
attributes for li the elements under the chosen-results
list are shifted by one (1, 2, 3… instead of 0, 1, 2…). Selection works the first time – I’m guessing because the placeholder option is in the array and shifting all the other elements – but every subsequent selection actually assigns the value after the selected value to the model (click on the second option, and the model is assigned the value for the third option). Picking the last value causes JQuery to throw an error.
How to reproduce:
Open angular-chosen/example/index.html
Pick a value from “Chosen with static options”
Pick another one and watch the model update to the value after it (or if the value selected is the last one, see JQuery throw an error in the console)
I’ll try to see if I can fix it.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top GitHub Comments
I don’t know the exact cause, but I figured out a fix for it. and I cannot believe how dumb this is:
I started thinking the issue may be the null li that is created when $scope.product has no value during init. So I figured that if I gave it a value before loading chosen that it would fix the issue. I tried this and it worked! I was astounded I though I would at least need to add
seleced="selected"
to the option. If this didn’t work I was going to addng-init="product = products[0]"
I think that this issue is covered in the recent documentation. Just add an empty valued option element: