1

Help needed, how to hide all results of a view when filter value is empty, after search button pressed.

(I have this: Set Advanced | Exposed Form | Exposed Form Style to input required. Not working well. When open view OK, but for empty search field, and search button pressed all appear)

I know there are lot of solutions here: (5 years old) https://www.drupal.org/node/358546 but I can't find those options in views in Drupal 7.

Can somone provide a working solution for Drupal 7 and Views version 7.x-3.x?

Explain question, end the operator for VIN and kod sterownika set to: "is equal to"

2

Edit your view and then set the "Exposed form style" to basic.

enter image description here

enter image description here

enter image description here

Hope that helps!

  • I have like that, but this is good for open new fresh view, there will be no rows. When you will press "search" and you will have empty filter fields, your view will return all rows...I need to return nothing till filter field is empty – mbahojlo Aug 27 '14 at 19:49
  • On the last image above just check the "Include reset button" checklist. Now when someone wants to go back to empty filters they will click the reset button. This should take them back to the view as it starts out. If configure like the rest of the images above it will start back at empty. – FatGuyLaughing Aug 27 '14 at 20:51
  • We probably do not understand well. I do not want the search results if the search field is empty. To explain this please do view on users entity, provide search field by email. Please set everything as showed on the pictures, then press the search button, and you will see all users as a result... And I wanted empty result until someone type part of the email in the filter field – mbahojlo Aug 28 '14 at 7:36
  • Ok, sorry about the misunderstanding. I'm not sure how to do that. – FatGuyLaughing Aug 28 '14 at 14:23
0

Ok till someone provide better solution

I create this one, and it's working :) It is important that i heave "is equal to" in VIN search field, so when I inject "X" as a value, if there is no conditions this will solve my problem.

function hook_views_query_alter(&$view, &$query) {

  if ($view->name == 'my_view_name') {

      //print_r($query);
      if (!isset($query->where[1]['conditions'][0] ))
      {
           $query->where[1]['conditions'][0] = array(
                                'field' => 'guarantee.vin',
                                'value' => 'X',
                                'operator' =>'LIKE' 
                            );
      }
  }
}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.