Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How to make the exposed filter in the table wizard view a drop down menu or select list instead of simple textfield?
Comments
Comment #1
lina.irshaid CreditAttribution: lina.irshaid commentedComment #2
paadamson CreditAttribution: paadamson commentedHi,
I created a module and used hook_form_views_exposed_form_alter()
You can then manipulate the form as you would any other:
$form['element']['#type'] = 'select';
$form['element']['#options'] = $my_array;
etc
Comment #3
achrelam CreditAttribution: achrelam commentedHi Paul,
Am new to drupal, am trying to implement a new module to use hook_form_views_exposed_form_alter() as you did, but i cant find a good example.
I have the same issue, after the import from my table via tw, In the view generated, i can't use a drop down list or checkboxes instead of the normal text field.
I had a look at the filter handler, i also tried to use the php filter but i cant solve the problem.
Any help from you will be reaally appreciated
Thx,
Comment #4
paadamson CreditAttribution: paadamson commentedIn your module (newmodule), create the function with the hook and inside the function make sure you're working on the correct form:
This will then let you work on the form via the form API like you would any other form within Drupal.
If you have a textfield called 'names' you can make this autocomplete by adding an autocomplete attribute:
Or replace the element with a select list:
Here we do our own query on a table and pull it into an array ($names), then build a select element on the form and populate it with the array we just make.
There may be an easier way to make all this work, but I've found this manual method handy when all else fails.
Comment #5
brammm CreditAttribution: brammm commentedThank you so much!
I've made a select list using the db-query, works perfectly!
Much appreciated!