I used to be able to have a list (text) field type attached to users (checkboxes in this case), but no matter what I do views will not treat multiple values for an argument separated with the "+" sign as multiple values even when the "Allow multiple values" checkbox is checked. The generated SQL query is obviously incorrect but I can't figure out where this is generated in the handler code.

In my below use-case, field_admin_groups is a list (text) of checkboxes with text keys (e.g. staff|Staff) attached to users and I'd like the view to accept multiple of these arguments (e.g. to return 'staff' and 'faculty_nonsenate' types), but the resulting SQL simply retains the + sign in the WHERE clause rather than separating into IN ('staff', 'faculty_nonsenate').

SELECT users.name AS users_name, users.uid AS uid, users.created AS users_created
FROM
{users} users
LEFT JOIN {field_data_field_admin_group} field_data_field_admin_group ON users.uid = field_data_field_admin_group.entity_id AND (field_data_field_admin_group.entity_type = 'user' AND field_data_field_admin_group.deleted = '0')
WHERE (( (field_data_field_admin_group.field_admin_group_value = 'staff+faculty_nonsenate' ) )AND(( (users.status <> '0') )))
ORDER BY users_created DESC

With other fields that take numerical values, I have "Allow multiple values" set on contextual filters and this works as designed. I can't get any multiple string values to work. Have I missed something obvious?

Files: 
CommentFileSizeAuthor
#18 views.1534720.2.patch902 bytespwaterz
FAILED: [[SimpleTest]]: [MySQL] 1,552 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#10 views.1534720.1.patch902 bytespbusch
Test request sent.
[ View ]
#9 multivalue-blanks.patch802 bytesschildi
Test request sent.
[ View ]

Comments

Status:Active» Closed (works as designed)

Most text fields do not support the phrase breaking method (which is the + or ,) in arguments. Typically that's only used for numeric fields, though some very particular text fields might support it.

Thanks for explaining. It might be good to document/explain this somehow since the option shows in the UI as the "Allow multiple values" checkbox.

From my understanding this is a duplicate of #1424500: Transform spaces to dashes in URL in list fields does not work so i would be happy if you could try out that patch on a site backup.

@dawnehner. I don't think #1424500 is a duplicate of the issue njcheng has raised.

I will re-iterate as even if the functionality is as designed ( as per Merlin's comment ) the Views interface leads one to believe it should work, and this has cost me several hours of misguided investigation which it would be good to remedy for others.

I have a multi-value field of type 'List (text)'. I have added this field as a contextual filter and selected the 'Allow multiple values' checkbox which states :

If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).

However when I access the path with using multiple values separated by either '+' or ','characters' ( e.g. my_view_path/cf1+cf2 )the Where clause Views generates looks like :

WHERE (( (field_data_field_sector.field_sector_value = 'cf1+cf2' ) )AND(( (node.status = '1') AND (node.type IN  ('person')) )))

In other words the operator is simply integrated as a simple character into the string matching query.

IMHO this should either work ( ideal ! ), the interface should make it impossible to configure, or the help text should have a warning that might save people plenty of time.

I am changing this issue to open so it gets one more chance to be resolved.

Thanks for all your efforts on Views.

Status:Closed (works as designed)» Active

Whoops. Didn't change status.

I have the same problem when I try to use multiple values from a List (String) field where the key is a string and not an int (using ints as Keys is not an option for me).

I have solved this by adapting the regex in the views_break_phrase method and commenting out the check for numeric values.

In my opinion there should be a check if a List has Strings or ints as keys and the according method should be called.

Cheers
Chris

@stylesuxx
From my unterstanding this should be fixed in the 7.x-3.x-dev version....

It is not fixed at all in version "2012-Aug-09".
A blank in a string is still handled as a (logical) separator in a contextual filter. For example, in my case the title string
Rheinisch-Bergischer Kalender
is converted (multiple values switched to ON) for the query to
(biblio.biblio_secondary_title IN  ('Rheinisch-Bergischer', 'Kalender'))

So, it looks that a blank is handled as an OR/IN operator.

Checking the "+" operator (should result in an OR / IN) the following contextual filter value
Rheinisch-Bergischer Kalender+XYZ
yields to
biblio.biblio_secondary_title IN  ('Rheinisch Bergischer', 'Kalender', 'XYZ')

Switching "Transform spaces to dashes in URL" to ON does not help. Just additional strange effects:
(biblio.biblio_secondary_title IN  ('Rheinisch', 'Bergischer', 'Kalender', 'XYZ'))

EDIT:
Having a look at file views/includes/handlers.inc in function about line 1085 you see

  // Determine if the string has 'or' operators (plus signs) or 'and' operators
  // (commas) and split the string accordingly. If we have an 'and' operator,
  // spaces are treated as part of the word being split, but otherwise they are
  // treated the same as a plus sign.
  $or_wildcard = '[^\s+,]';
  $and_wildcard = '[^+,]';
  if (preg_match("/^({$or_wildcard}+[+ ])+{$or_wildcard}+$/", $str)) {
    $handler->operator = 'or';
    $handler->value = preg_split('/[+ ]/', $str);
  }

The comment here describes that a space is handled as an OR operator if a plus sign is found in the string.
I don't have any idea why it is treated this way, but wiping out the special handling of blanks leads to

  $or_wildcard = '[^+,]';
  $and_wildcard = '[^+,]';
  if (preg_match("/^({$or_wildcard}+[+])+{$or_wildcard}+$/", $str)) {
    $handler->operator = 'or';
    $handler->value = preg_split('/[+]/', $str);
  }

what yields in a where clause
AND (biblio.biblio_secondary_title IN  ('Rheinisch-Bergischer Kalender', 'Bergischer Kalender'))
what looks really fine to me.

Someone who is familiar with the code should check this.

StatusFileSize
new802 bytes
Test request sent.
[ View ]

for simplicity, here is the patch

StatusFileSize
new902 bytes
Test request sent.
[ View ]

Status:Active» Needs review
Issue tags:-multiple values, -contextual filter+Needs tests

.

Version:7.x-3.3» 7.x-3.5
Status:Needs review» Needs work

I'm having a similar problem. I'm trying to accept multiple uid values and it doesn't work. I made the changes from your patch in Views 7.x-3.5 and it didn't make a difference. I will take a look at this and see if I can figure it out.

This doesn't really solve the root problem here, so I created a new issue with a patch that allows you to accept multiple User IDs as a Contextual Filter.

http://drupal.org/node/1798270

Just posting here in case it helps someone.

Status:Needs work» Closed (duplicate)

Marking as duplicate based on #13.

I don't think this is a duplicate... This issue is about spaces being treated as separators when using multiple valued contextual filters. The issue in #13 is about using multiple UID's in contextual filters, which don't have spaces. Am I mistaken?

Either way, #10 worked for me.

#10 worked for me too.

It looks strange the logic after views_break_phrase_string() method with spaces, which is to consider spaces as part of the string for 'AND', but not for 'OR' logical operators.

I also don't understand how it can be a duplicate of Contextual Filter User ID Allow Multiple. I tested the patch in the other issue and it didn't solve this one. weekbeforenext, could you explain us why the two issues are related?

Yes, this is not necessarily a duplicate issue. I was trying to accept multiple user IDs or usernames in a contextual filter. Selecting the "Allow Multiple values" checkbox didn't completely solve my problem because there was no logic to handle multiple values. I originally posted here because I thought the Allow Multiple values should have worked for me. I posted a second message to share a solution to my problem that is related, for people that found this thread in their search. To be able to accept multiple user IDs or usernames, you have to select the "Allow Multiple values" in addition to my changes in the other issue.

Status:Closed (duplicate)» Needs review
StatusFileSize
new902 bytes
FAILED: [[SimpleTest]]: [MySQL] 1,552 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

I can confirm the bug noted in #8. Currently if you have space in a contextual filter it breaks spaces into separate arguments. I have updated the patch against views 3.7.

The last submitted patch, views.1534720.2.patch, failed testing.

Status:Needs work» Needs review

#18: views.1534720.2.patch queued for re-testing.

Status:Needs review» Needs work

The last submitted patch, views.1534720.2.patch, failed testing.