By end user on
I'm looking for a module that will turn a text field that is used to collect say a city name through a text field when a node is created into a drop down list when that field is exposed in views.
Also I need the module to only list each entry once. So say I have a field called (city name) and there are 20 nodes with the city name Vancouver I only need to show this once in the drop down.
I was going to use the Auto-complete Widget module but after testing seems it doesn't work with Contextual filters and I think a drop down would be better for people with JS turned off.
I've included a screenshot of what I'm looking for.
Comments
Hi, You need to implement
Hi,
You need to implement hook_form_alter in your module to alter your views exposed form. It will change the textfield to select list and set options fetched from the database.
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
I would but know nothing
I would but know nothing about php. Saw a few examples of modules people wrote but they were dor D6/V2.
Should have stated I'll pay $50 for the module.
Job has been completed.
Job has been completed.
Thank You.
For those who have the same
For those who have the same need of turning a text field into a drop down when exposed in views here's the modules. You will need to change
$field_id = 'field_exact_location';to the name of your content types text field.
There are the module files. You can name the module to suit your needs.
dd_city.info file
dd_city.module
Create the files, upload them to your modules directory and activate the module.
Code for addressfield module
I got your module to work perfect with a regular text field. But Im trying to use the Address module for D7 and i cant seem to get it right. I get the drop down using the code below but there is nothing in it. I get an error of
I am looking to pull the state (administrative_area) into a dropdown filter selection.
MODULE CODE
Any help would be greatly appreciated.
Regards
Just in case anyone's
Just in case anyone's wondering, the following function works, based on above.
Works nicely, but need to build on current view
Thanks for this code - I tried it out and it worked almost out of the box.
I have a need, however, for it to list the admin areas that apply only to my current view. My 'current view' lists a number of nodes, each with its own address (field). I then want the user to be able to apply a filter that shows the admin areas used by the current view of nodes (so there are no empty results).
Is it a simple job to add that to this module?
I don't want to spend ages if what I'm trying to do is simply not possible.
Thanks for looking...
Martin
adding multiselect
@end user's solution (in the comment titled "For those who have the same") works great for me for one of my scenarios, but I have another which requires a multiselect drop down. I can convert the drop down to multiselect, but then my form stops working - even if I only choose one of the options :-/ Has anyone tried something like this before? (By "stops working", I mean that I get no results when I submit the form.)
Hi, I've been working with
Hi, I've been working with Drupal for some time, but I'm still rubbish at the very back end bits. All I would like to know is, if I want to expose the content's titles as a dropdown list, what would I use in the field $field_id = 'field_exact_location'; ?
any help would be greatly appreciated
Thanks!
Please help me with the same problem.....
Kindly help me to get drop down of the Referenced entity Node title as an dropdown in drupal views
Perfect, thanks for providing
Perfect, thanks for providing the code, we just need to add check to see if query results are not empty, then proceed or return otherwise
thanks for that, needed it
thanks for that, needed it for another entity type but easily changed it.
Hi - changing entity exposed filter to dropdown
https://drupal.org/comment/reply/1549250#comment-form
Hi Junkbox - I noticed you said you changed the code that this kind gentleman posted here so this would work on an entity instead of a node. Was wondering if you could perhaps share with me what you did as I cannot seem to get this working! If not, no worries.
Thanks
Ben
Thanks for sharing! (I wrote
Thanks for sharing! (I wrote it if anyone has questions about it)
http://www.trailheadinteractive.com
Grouping values
When you need to have grouped-by values (duplicates filtered) you may use this function instead:
Hi, Isn't using Field text
Hi,
Isn't using Field text (list) enough for D7?
greetings, Martijn
turning text field to drop down list in views exposed filter...
function hook_form_views_exposed_form_alter(&$form, &$form_state){
if($form['#id']==){ // view exposed form id has been taken for putting up a condition
$result = db_select('node', 'n')
->distinct()
->fields('n',array('nid','title')) //nid & title as per my requirement, get your fields as per requirement
->condition('n.type', 'events','=')
->execute()
->fetchAll();
$data_variable=array(); //simple array variable to store the result data
$data_variable['select']="-Select-"; //to set a default value
foreach ($result as $key=> $val){
$data_variable[$val->title]=$val->title;
}
$form['
']=array( //you can put your form field machine name, which you want to convert to drop down list.
'#type' => 'select', // here changed the field type to select.
'#options' =>$data_variable, // and then passed the values stored in the data_variable
'#default_value' => 'select', //setting default value for the new drop down list
);
}
}
While changing a view exposed filter form field from text to select list the above code worked for me, also there was an observation, that if there is no default value entered in the text box then "An illegal choice has been detected. Please contact the site administrator." would appear.
So there has to be a default value in the text field. Now, the newly customized form field(drop down) also needs to have a default value.
That also has been mentioned in the above code.
Note: both the default values i;e in the text field and the drop down list, has be same.
In my case "select".
Hope this will help you.
I was able to turn a list of
I was able to turn a list of nodes into an exposed filter using the Views Reference Filter module.
If somebody wants to do this
If somebody wants to do this in Drupal 8 quick & dirty via theme hook:
THEMENAME.theme