Problem/Motivation

Using multi-select widget with user-reference field. List of users presented in "Available Options" column is generated by a view. Configured in structure > content type > my_content_type > manage fields > my_multiselect_field > field settings > views - users that can be referenced

(no filtering based on user roles that can be referenced or user statuses that can be referenced)
Selecting multiple users works fine.
Selections are displayed properly in the right column of "Selected Options" until the node is saved.
Once the node is saved the field data from the view is replaced with (what appears to be HTML).

  • The list of users matching the criteria of the view appear fine in the left column of "Available Options." (see image 1 attached)
  • Able to select users from list and move them to the "Selected Options" column fine. (see image 2 attached)
  • Saving node writes to the database fine and displays on the node properly
  • Editing saved nodes fails to display the fielded data but instead appears to display HTML (see image 3 attached)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anou’s picture

Status: Active » Needs review
FileSize
2.37 KB

Hello,
I post my patch here because your problem was also mine but with entity reference generated by views. My patch also resolve an Notice : Undefined index: nid and makes multiselect language aware.

Try it and tell me if everything all right.

anou’s picture

Title: inability to deselect referenced users with multiselect when list is generated by views » Problem with multiselect when list is generated by views
Version: 7.x-1.9 » 7.x-1.x-dev

I changed the title a bit and the module version. Feel free to modify it again if I'm wrong.

JvE’s picture

Status: Needs work » Needs review
+++ b/multiselect.module
@@ -76,6 +76,9 @@ function multiselect_field_widget_form(&$form, &$form_state, $field, $instance,
+  //not used but you never know :-)
+  $handler = $field['settings']['handler'];

Do not add code clutter for no reason please.

+++ b/multiselect.module
@@ -86,18 +89,22 @@ function multiselect_field_widget_form(&$form, &$form_state, $field, $instance,
+  //Remove all tags from values. Very useful for views displays.

What is the issue with views displays? Does this still allow me to have options like "<Yes>" and "<No>"?

+++ b/multiselect.module
@@ -86,18 +89,22 @@ function multiselect_field_widget_form(&$form, &$form_state, $field, $instance,
+  ¶

Trailing whitespace.

+++ b/multiselect.module
@@ -138,8 +145,8 @@ function _multiselect_after_build($element, $form_state) {
+    foreach ($form_state['values'][$element['#field_name']][$element['#language']] as $nid) {

Good one, but is $element['#language'] guaranteed by spec to be always set?

I am currently trying out jquery_ui_multiselect so I'm not able to do much testing on this one.

anou’s picture

Thank you for your report.

  1. Sorry for the useless code. I first thought that to handle the <tags /> issue with views, I had to do some "if" statement with the $handler... I removed it.
  2. The issue with views is shown by screenshot #3 as exposed by knowledges33ker. Views adds spans when displaying items in a select. And sorry but your comment was truncated and I don't know what you meant by
    options like "" and ""
  3. White space removed
  4. For the language, my first thought was to use the global $language. But the global var can be different from the #element['language']. So to guarantee that it will be always set I've added some if statement.

Here's my patch modified.

robby.griffin’s picture

Status: Needs review » Needs work

Thanks for making these patches, anou! It is incredibly helpful for me. I just applied your patches, which made me realize one big issue for anyone trying to test your patch, you rolled your newest patch against your customized version of the module rather than the dev version of the module. In order to make this work, I had to apply the first patch, and then apply the second patch. Could you re-roll the patch so that testers can just use the most recent one? I'll be testing this in the coming weeks some more to see how it holds up.

anou’s picture

Hello Robby,
here's a new patch with all my modifications in one place. I think it's ok... please let me know if it's what you want it. Thanks.

NWOM’s picture

I had the nid issue. The patch works perfectly. Thanks!

nfriend’s picture

The Patch in #6 worked for me as well. Just be sure you apply it to DEV version. Might be ready for a new version??

Thanks for this module.

Neil

attheshow’s picture

Status: Needs review » Needs work

I just added this to the development version.

attheshow’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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