I have a node edit form where I allow up to 3 terms to be selected, but with the chosen module it will keep letting me choose terms and not until I save it does it give any error. I would think that after 3 terms are selected it would prevent me from selecting more.

CommentFileSizeAuthor
#2 chosen.miscellaneous.2035723-2.patch2.14 KBHydra
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hydra’s picture

Status: Active » Needs work

Agree, this would be the suggested behavior.
Using the max_selected_options option, this should be possible. It will be kinda tricky to get this information out of the select field.

$(".chosen-select").chosen({max_selected_options: n});
Hydra’s picture

Version: 7.x-2.0-alpha2 » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
2.14 KB

Okay, we came up with a solution to transfer field specific settings to the plugin in #2023007: Separate minimum number of elements for single and multiselect., which can simply be adapted for this case. The following patch should transfer the field maximum values setting to chosens "max_selected_options" like I suggested in #1. Therefor chosen should stop letting you selecting more values in multivalue fields.

Harlor’s picture

Status: Needs review » Reviewed & tested by the community

well this seems to work well. Hopefully it will be merged into the next stable release.

Hydra’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/chosen.module
@@ -166,6 +166,14 @@ function chosen_element_info_alter(&$info) {
+  dsm($field_info['cardinality']);

UPS, okay I removed the dsm I forgot. Thanks for your review. Pushed to 7.x-2.x
http://drupalcode.org/project/chosen.git/commit/4b744f7

xbrianx’s picture

I just updated to the new dev version and am still able to load more terms than allowed. When saving the content I received this error:

Notice: Undefined index: #multiple in chosen_pre_render_select() (line 178 of /home/site/public_html/testing/sites/all/modules/chosen/chosen.module).

Hydra’s picture

Well this looks like you did not clear your cache ;)

xbrianx’s picture

I wish that was the case :( . I cleared the cache and ran updates twice. I didn't see an update to the library though maybe I need to do that?

Hydra’s picture

Status: Fixed » Postponed (maintainer needs more info)
xbrianx’s picture

Great, I just installed the latest dev version and all is good now.

Hydra’s picture

Status: Postponed (maintainer needs more info) » Fixed

Okay nice, so this is finaly fixed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

goldlilys’s picture

Issue summary: View changes

For some reason, the maximum option is gone from the chosen settings page and only see the minimum. Was this not added to the new version?

goldlilys’s picture

Component: Miscellaneous » User interface
Status: Closed (fixed) » Needs work
gauravkhambhala’s picture

Yes, Correct. The latest beta release does not show maximum allowed option. Probably above patch needs to be revised and applied to latest code.

https://www.drupal.org/node/2023007 This issue talks about setting minimum. We should have an option for maximum also. I will see if I can create a patch for this.

  • Hydra committed 4b744f7 on 8.x-2.x
    Issue #2035723 by Hydra | xbrianx: Fixed Chosen Not Respecting Maximum...