Comments

Snehal Brahmbhatt’s picture

You can use "hook_form_views_exposed_form_alter(&$form, &$form_state, $form_id)" function for your purpose.

i.e.

function custom_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
        if(($form_id == 'views_exposed_form')) { 
                if(count($form['field_term_artist_tid']['#options']) <= 2) {
                        unset($form['#info']);
                        unset($form['field_term_artist_tid']);
                        unset($form['submit']);
                }
        }
}

Hope this helps you.

Thanks,
Snehal Brahmbhatt | AddWeb Solution
https://www.drupal.org/user/3147795/track

joostvdl’s picture

Issue summary: View changes

It is not working correctly:
When I unset the above list (changed the fieldnames) I get these errors:

Notice: Undefined index: #info in template_preprocess_views_exposed_form() (regel 950 van /var/www/clients/client5/web29/web/sites/all/modules/contrib/views/theme/theme.inc).
Warning: Invalid argument supplied for foreach() in template_preprocess_views_exposed_form() (regel 950 van /var/www/clients/client5/web29/web/sites/all/modules/contrib/views/theme/theme.inc).
Warning: array_map(): Argument #2 should be an array in views_handler_filter_selective->query() (regel 196 van /var/www/clients/client5/web29/web/sites/all/modules/contrib/views_selective_filters/views_handler_filter_selective.inc).

When I change the unset to remove the child from #info I get the following error:

Warning: array_map(): Argument #2 should be an array in views_handler_filter_selective->query() (regel 196 van /var/www/clients/client5/web29/web/sites/all/modules/contrib/views_selective_filters/views_handler_filter_selective.inc).

saurabh.dhariwal’s picture

Hope this helps you.

function custom_popups_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
        if(($form_id == 'views_exposed_form')) {
                        if(isset($form['tid']['#options']) && !empty($form['tid']['#options'])){
                if(count($form['tid']['#options']) < 2) {
                                        $form['#attributes']['class'][] = 'test';
                }
        }
        }
}

then set style to "test class".

.test{display:none}

Thanks!

renatog’s picture

Status: Active » Reviewed & tested by the community

#3 liked good.

Thank you very much @saurabhdhariwal.

renatog’s picture

Status: Reviewed & tested by the community » Fixed

@joostvdl, if have any question please comment here ok?

Good Work and Good Week.

Regards.

Status: Fixed » Closed (fixed)

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