The use case is allowing a user to to copy and paste or zap a list of barcoded id's into an exposed filter text-area, then submit and have all the corresponding records returned for further processing, i.e. updated with VBO.

The field being filtered on is a unique identifier so each record has it's own value, making a list or other select impractical. The default exposed filter works perfectly to filter individual records. However, when using an exposed filter on a text-field, views 3.7 only allows a single value as an input. When I try forcing multiple values separated with dashes, spaces, plus signs, ampersands, commas, , etc. only the record for the first value in the series is returned.

A contextual filter works ok as a workaround, but with 9-digit unique identifiers, the url quickly exceeds apache's limit on url length. And building the url in excel is a little too cumbersome to be considered a practical solution.

A Google search for "multiple values views exposed filter" returns a couple of proposed custom modules but they all deal with D6. Here's an example: http://www.metaltoad.com/blog/passing-multiple-values-through-exposed-fi...

Is allow multiple values for text-field exposed filters a planned feature? Has anyone who's implemented this willing to share?

Thank you,

Damian

Comments

ravi.kumar88’s picture

Hi Damian,
You can allow multiple values in the text-field exposed filter using the "Contains any word" operator while making it as Exposed filter.In the case it takes multiple values separated by any of the separators you mentioned above like dashes, spaces, plus signs, ampersands, commas, etc.In that case the SQL query is written with an OR operator for every word.
Thanks
Ravi

keyswebsites’s picture

Thanks, Ravi! I changed my field type from integer to long text and can now pass multiples values to a text-field exposed filter in views. However, the exposed filter widget is still a single line text field and limits/truncates my input (search terms, in this case user ID's) to about 100 characters. As an aside, I installed Views ExPost to overcome the url limitations.

Any thought on how to display a text-area instead of a text-field in the exposed filter, and/or allow more characters in the existing widget?

dkinzer’s picture

Damien,

not sure you still need this, but You can always alter the exposed field via hook_form_alter:

For example

/**
 * Implements hook_form_alter().
 */
function company_form_alter(&$form, &$form_state, $form_id) {
  $company_form->hookForm();
  if ($form_id == 'views_exposed_form' && $form['#action'] == '/company/multi-search') {
    $form['company_name']['#type'] = 'textarea';
  }
}
doors’s picture

Issue summary: View changes

Did anybody find a way to implement this?

I want to allow user to add multiple search options for an exposed field for any operator type. So if for an age field the user want to find records with ages between '1-10', '20-30' and '40-50' they should be able to do it with one query instead of doing three separate searches.

SathyaSheela’s picture

--- views_handler_filter_combine.inc 2017-02-22 22:45:15.000000000 +0530
+++ views_handler_filter_combine-new.inc 2017-06-06 11:03:52.711053675 +0530
@@ -107,20 +107,21 @@
return;
}

- preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
+ //preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
+ $matches = explode(",",$this->value);
foreach ($matches as $match) {
$phrase = FALSE;
// Strip off phrase quotes.
- if ($match[2]{0} == '"') {
- $match[2] = substr($match[2], 1, -1);
- $phrase = TRUE;
- }
- $words = trim($match[2], ',?!();:-');
- $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
+ //if ($match[2]{0} == '"') {
+ // $match[2] = substr($match[2], 1, -1);
+ // $phrase = TRUE;
+ //}
+ //$words = trim($match[2], ',?!();:-');
+ //$words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
$placeholder = $this->placeholder();
- foreach ($words as $word) {
+ //foreach ($words as $word) {
$where->where($field . " LIKE $placeholder", array($placeholder => '%' . db_like(trim($word, " ,!?")) . '%'));
- }
+ //}
}

if (!$where) {

gouthamraon’s picture

You can pass multiple values using contextual filter,

Select Raw Value from Url and select PathComponent/arugument.

Below we have More section from that you can check Allow multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).

http://example.com/some-path/24+25

or

http://example.com/some-path/24,25

ravimalviya2000’s picture

You can pass multiple values using contextual filter.
Please below steps:
1) Section - When the filter value is NOT in the URL : Please select "Display all results for the specified field"
2) Section - More - You need to check checkbox - 'Allow multiple values'

After that you can able to find http://example.com/some-path/24+25 or http://example.com/some-path/24,25