When activating chosen as the widget for a select list presenting data from entity reference, in my case a list of users with links to the user itself, a single user can be added normally (clicking in the field brings up the list to choose from). But after that no more can be added despite "number of values" for the field having been set to "unlimited", and this working fine when using other multiple select widgets for the same field.

Comments

czigor’s picture

I have the same here with a List(text) field.

I populate the options from code via hook_field_widget_form_alter but I make sure that my hook runs before chosen's.

czigor’s picture

I have found the solution for my problem which seems to be a core one: if the allowed_values of an unlimited select field is empty, the widget will be single even if I populate the options via hook_form_alter or hook_field_widget_form_alter.

pmusaraj’s picture

Another way to fix this is to destroy and recreate the chosen element with a max_selected_options set via javascript, in a behaviour. Like this:
$('.field-name-field-themes select').chosen('destroy').chosen({ max_selected_options: 10 });

This is akin to using not using any of the default chosen settings from the module though.

bunthorne’s picture

Issue summary: View changes

I don't have any problems adding multiple selections in an Entity Reference list, both in the add/edit forms and in the Views exposed filters. I have been using Chosen successfully in this way for over a year.

Can you recreate the problem as a bug report, or is it a problem writing a custom module? I suggest testing a simple new Content Type with one Entity Reference field set with unlimited values, then go to the Add Content form for the test type.

Dave Reid’s picture

Status: Active » Closed (cannot reproduce)

I cannot duplicate this with current version of Chosen + Entity reference select widget with unlimited cardinality.

BarisW’s picture

Status: Closed (cannot reproduce) » Active

Not sure if it is related, but let's re-open to make sure.

I have a unlimited chosen field with user relations. When I click the chosen element, the dropdown appears so I can select a user. When I then try to select another user, this is not possible. Only after I click outside the chosen element, I can select another user. The chosen element doesn't seem to handle selecting multiple items without leaving the chosen box in between.

BarisW’s picture

For now I fixed it using a custom JS function, like this: https://github.com/harvesthq/chosen/issues/2310#issuecomment-93372444

BarisW’s picture

Status: Active » Closed (cannot reproduce)

Sorry for the noise. It seems to be a CSS issue in my project. When I switch to bartik, all works fine.