chosen js dropdown last select issue

Error on last item selection

When I select last item on second time. It is giving an error “Uncaught TypeError: Cannot set property ‘selected’ of undefined” on every chosen.

solution

I had the same problem with this behavior. I used the following as workaround:

  <select 
    chosen
    data-placeholder="Placeholder"
    ng-model="myValue"
    ng-options="item.name for item in itemList"
    >
    <option value=""></option>
  </select> 
  {{myValue.name}}

And options from:

$scope.itemList = ['Option1', 'Option2', 'Option3'];        

To:

$scope.itemList = [{name: 'Option1'}, {name: 'Option2'}, {name: 'Option3'}];   

 OR

Whilst not ideal, I found the solution to be similar as whats referenced above.

Instead of using hardcoded <option> use ng-options with 1 disabled option like so:

<select chosen ng-model="model" ng-options="o as o for o in array_of_options">
  <option disabled></option>
</select>

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s