I'm not sure what's happening here. I have chosen working great on another site, but I've recently taken over a new site that has all kinds of fun quirks. One being, on multi-select chosen fields, none is an option. So I can choose Option 1, Option 2 and none. All at once.

Can anyone give me a heads up of where I might be able to fix that? It would be greatly appreciated. I'm certain I'm not finding a bug, but I can't find anyone with a similar issue when I search. Maybe it's something simple I'm not realizing.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zilla’s picture

is it possible that this is specific to the field for the taxonomy (or select list) - where the field is not required and so presents a 'none' option?

stupiddingo’s picture

Issue summary: View changes

You can unset the none option in your own module:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_FORM_ID_alter(&$form, &$form_state) {
    // For Organic Groups
    unset($form['og_group_ref'][LANGUAGE_NONE][0]['default']['#options']['_none']);
    // For Taxonomy
   unset($form['field_myfield'][LANGUAGE_NONE]['#options']['_none']);
}

I image one could implement this inside of chosen as well removing _none from all chosen widgets.

stupiddingo’s picture

Status: Active » Needs review
FileSize
652 bytes

Here's an attempt at adding this functionality to chosen. Works in the tests I have available. Needs review.

Elin Yordanov’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Category: Support request » Bug report
FileSize
582 bytes

Attached is a new patch for the current 7.x-2.x-dev version. Please review.

caminadaf’s picture

Status: Needs review » Reviewed & tested by the community

Worked perfectly. +1 RTBC

The last submitted patch, 3: None_showing_as_option-2117827-3.patch, failed testing.

maximpodorov’s picture

FileSize
582 bytes

I just renamed the patch file to become more standardized.

carolpettirossi’s picture

#7 worked for me. +1 RTBC

nagy.balint’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, seems to work fine, Committed.

mr.york’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
Assigned: Unassigned » mr.york
Status: Fixed » Patch (to be ported)
FileSize
723 bytes

Drupal 8 version.

nagy.balint’s picture

About the Drupal 8 port: So far this patch and the related cardinality setup in chosen code is not working, cause entity type is not available in the pre render function, so we cannot load the field settings (as in drupal 8 field with same name can be in different entities).

mr.york’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.19 KB

I corrected the field config loading, but it needs the #2678824: The widget form element does not contain the bundle and the entity type (core patch) to make it work actually.

nagy.balint’s picture

Status: Needs review » Postponed

Committed the patch.
Since it has isset checks, it wont cause any problem if the core patch is not in yet, and the current code that it replaces also does not work.

But this way, once the core patch is in, it will just start to work, or if we find another way then we can just make another patch that continues from here.

Putting it on postponed til we have news on the core patch.

  • nagy.balint committed 4d1ac81 on 8.x-2.x authored by mr.york
    Issue #2117827 by mr.york: "None" showing up as an option in multiselect...
esmith818’s picture

Is it possible that this patch (D7) is indirectly responsible for a possible bug on iOS devices when using a multi-select field that has no value by default and is not required?

On other platforms, an empty value (1-initial-value.png) remains intact unless an option(s) is manually selected in the list. But on iOS devices, once the user clicks the field, the first selection is automatically chosen (2-click-field.png) and the user must choose "Done" and then re-enter the list to manually uncheck the first option (4-reenter-to-fix.png). If they also manually choose another value (3-click-value.png), by default TWO values are selected.

I had thought this was due to iOS' unique UI of scrolling through options, but I see that the same behavior is NOT present on the sample multi-select at http://harvesthq.github.io/chosen/

If this issue is addressed elsewhere, please direct me to a link. I could not find a solution via several searches.

jhedstrom’s picture

Over in #2678824: The widget form element does not contain the bundle and the entity type, it appears that there is actually access to everything a contrib module needs here. This patch adds the elements via the hook_field_widget_form_alter(), and adds a test. If this is good, then that core patch is no longer technically needed.

Status: Needs review » Needs work

The last submitted patch, 17: 2117827-17.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
2.43 KB
2.24 KB
4.97 KB

There was a typo in the new test so it wasn't run, and the test was also using the wrong assertion method. There were also tests explicitly checking for the _none functionality on multivalue widgets, so this patch removes those.

The last submitted patch, 19: 2117827-19-TEST-ONLY.patch, failed testing.

jhedstrom’s picture

FileSize
935 bytes
5.77 KB

The patch in #19 has issues with base field definitions. On base fields, the bundle property is null. The updated patch only uses the #bundle property to fetch the cardinality, and unsets the _none option for all multiselect fields.

mr.york’s picture

Assigned: mr.york » Unassigned
Status: Needs review » Reviewed & tested by the community

Works for me. Good patch.

  • nagy.balint committed 43af4c5 on 8.x-2.x authored by jhedstrom
    Issue #2117827 by jhedstrom, mr.york, stupiddingo, Елин Й., maximpodorov...
nagy.balint’s picture

Status: Reviewed & tested by the community » Fixed

Thanks.

Status: Fixed » Closed (fixed)

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

nvahalik’s picture

Note that the 2.x branch which applies this fix will break if you are already removing these values within your code. The module doesn't test to see if that option even exists and it will throw a fatal error if it tries to remove it and it is not there.