1

I have a view with an exposed filter field. This field always shows the -Any- value. The data shown is dynamic so I cannot select the values to show. I have to remove that option in some way.

I've looked at this answer but this is for a form and I'm trying to do this for a views page of type chart. Anyway, I can't even dpm the form name as is said in the example.

My view name is x_report_plus_feature_dashboard and the display is page1.

How can I do this? Thanks!

EDIT:

I was able to remove the '-Any-' value with the following code:

function HOOK_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    unset ($form['field_MYFIELD_tid_selective']["#options"]['All']);
  }
}

But now I have a problem. When I go to the view, the data shown is still the same that was shown when -Any- was selected. For me it's ok to show the data for the first entry as default but how to do it?

  • The dpm() should work to figure out the form name. The views filters use the same Drupal forms API. There must be some issue with your custom module. – cleaver Nov 25 '15 at 17:44
  • Thanks for the help, cleaver. How can I get the form_id? Or is the the one I wrote above? – zephirus Nov 25 '15 at 18:02
1

Setting the exposed filter to required will remove the -Any- option.

  • Hi Chris, thanks for your answer. That exposed field was using Views Selective Filters and that wouldn't work. Anyway, I changed it to normal expose and the Any doesn't show. The only issue is when I don't have any terms. It gives me the error: An illegal choice has been detected. Please contact the site administrator. – zephirus Dec 2 '15 at 11:10

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.