By resting on
How do I create a views filter by node title but have it as a drop down (like filters under taxonomies) instead of a textbox?
How do I create a views filter by node title but have it as a drop down (like filters under taxonomies) instead of a textbox?
Comments
views search results as drop down
I think you want to show all search results in a drop down. I don't think any of the existing modules will be able to do that. You are better off creating a new module/hook for that or you can just modify the views template file.
However, if you are not aware of these techniques I can point you some handbooks.
-Babu
Drupal Projects showcase: http://paramprojects.com/website/drupal-servicesprojects
Promote Drupal with Tshirts/merchandise: http://paramprojects.com/drupalstore
Not search results as drop down
Hi thanks for replying. However I wasn't looking for the search results as drop down. But rather the filter itself.
It should appear like one of this: http://i293.photobucket.com/albums/mm64/emojunior101/select.jpg
The current default appears as a text box for users to input their search text. But I want it as a drop down with the node title pre-populated.
_
There's a couple of modules in the downloads area that enhance views exposed filters. if one of those doesn't do it, then you should be able to do it with hook_form_views_exposed_form_alter in a little custom module.
Could you tell as those modules?
You mentioned there exist few modules to enhance views exposed filters. could you list them?
thanks in advance.
_
One that i know of off hand is better_exposed_filters -- but you should be able to locate them pretty easily from the module's search page with 'exposed filters'.
I have this same issue and
I have this same issue and Better Exposed Filters didn't seem to add any kind of functionality for me at all. I'm thinking I have ghosts in my Views install, but does anyone have this working?
As far as I know there is no
As far as I know there is no way to do this with node titles.
Some people want it, but it seems the powers that be have decided it is not a good idea.
http://drupal.org/node/840512
So unless you can code, the only option for a exposed node title filter seems to be a blank text box, which leaves users guessing as to what they might want to search for.
Honestly, I would love it if it could be a standard option. I think it should be up to the site designers to decide if a dropdown is practical or not. After all, many items that do have drop downs, such as taxonomy terms, could also have a huge result set and become impractical for large numbers. But for sites where the number of nodes is small, a dropdown for node titles makes sense.
I am using a view in a block as an alternative. The view lists my node titles and each title is a link to its node.
Not perfect but it works, plus the view can have a filter as well.
The powers that be have spoken
The powers that be have spoken, and... uhhh... they changed their mind.
There is a hidden feature in the CTools module that makes a drop down menu a new View type. Enable ctools (http://drupal.org/project/ctools) and an extra "jump menu" option will "magically" and undocumentedly (?) appear in you views "Style" options.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
_
It might be picking nits, and the jump menu works great, but it's not a drop down exposed filter which will show up with other exposed filters on the filter form. For that you still need some form_alter code afaik.
I managed something very
I managed something very similar to this by adding a new text field with 'select widget' to the content type I wanted to filter by node title. Using php, I set the allowed values of this new field to populate the select list with all the node titles of from the content type. Leave the field as single value, not required, and no default value. Also hide it completely from users using permissions as it wont need to be accessed.
Then, add a simple 'triggered rule' with rules module. All the new rule needs in its settings is 'event > after saving new content'. Leave conditions empty. Then 'add action > populate a field' and select the field you just created. (don't give the action a value to populate the field with). Save the rule and make sure it's active.
Its a bit of a gaffa tape and cable ties way of doing it, but this basically clones the title to the text field when you save a new node. As the title is saved before the field is populated, it gets added to the list of 'allowed values' and rules can populate the field with it. In turn the new field is available to expose in views as drop down. (there are 2 options for the new field as a filter, use the one with - allowed values appending the field name and check 'force single')
Its not ideal, or particularly minimal... but works in my situation so I'm hoping it can help others.
Hi filthypixel
Can you post up the php code used? It would be much appreciated :D
Bret
Figured out the code
In my rule action I used this code to populate the hidden field:
Spoke to soon -
That will work to populate a TEXT field but not a SELECT field...
:/
something similar can be
something similar can be accomplished with http://drupal.org/project/computed_field
------
GiorgosK
Web Development
No population (selection)
This sounded like the solution to my problems, but my field isn't getting populated (i.e no option gets selected). But I can't see how it would know to select the option that had just been created anyway. Is there a step missing?
It looks like this is the same problem that bretglassett had. Did you ever find a solution?
Solved!
Finally cracked it! So for anyone who has the same problem...
Firstly, when populating the hidden field, you can't use things like
$node->title. Instead, you need to use the tokens, e.g.Secondly, if you're using a select list widget, you need to return the index of the option, not its value.
Therefore, it's also important to make sure your list of allowed values is keyed. Otherwise the default index (the position of the value in the select list) could change when adding or deleting options, which will mess up the values for your existing nodes!
So, I generated my Allowed Values as follows:
Then returned the index like this:
However, you may not need to use a select list widget anyway, as you can still set Allowed Values for a normal text field...
I'm confused...
Onein,
I tried to follow your instructions to get an exposed filter as a select list of node titles of a particular type but can't seem to figure out where I am screwing up...
If it isn't too much to ask, can you help me better understand how to implement your solution?
First, I assume your solution extends upon the solution mentioned by Scubox in the thread - I believe I need to create a text field for the content type whose titles I want to filter by. I have, and I have set it as a "Select List" widget. It is set to receive a single value, it's population is not required, and it has no default value.
Now, in Scubox's post he uses a "triggered rule" - do I need that for your solution? (this is where I was getting confused)
You have presented 3 code snippets - I believe I only need two of them as I AM intending to use a select list and therefore need to return a keyed value, right? If that is correct, am I right in saying that I only need to last two pieces of code you presented?
I tried to put the largest chunk of code you provided into the "Allowed Values", "PHP" area of the new text field I created. In the code snippet you provided I know I need to change content type mentioned (ie. 'your-node-type') - my content type is a 'file_docket_sales' object (as shown on my list of content types). I have removed the starting and ending php declarations when pasting it into "PHP" area. When I try and save the field it reloads to a "Page not found" error page. When I go a review the field to see if anything saved, none of the code I just entered is there. If I try another piece of PHP code in this field, it saves no problem - I'm no PHP developer and have no clue what would cause that behaviour. As a test, I tried removing the commend you had but got the same result.
I also and not sure where to put the last piece of code you entered - ie. where to "return the index".
I wanna be able to create a view that has an exposed filter with the titles of all nodes of type "file_docket_sales" as a "select list". I just can't figure out how you did it!
If you are able to help, I would appreciate it a lot.
Jump menu is the solution!
Take a look at this: http://stackoverflow.com/questions/3881718/drupal-views-exposed-filter-o...
Worked out for me! :)
--
Heitor Althmann
Drupal Developer
This is what worked for me:
This is what worked for me:
1) a text field with allowed value php :
(The interesting thing is that it needs "title" as key - identical to the value unless the views query tries to match the content nid with the field content - hence the change from Onein's code)
2) 2 rules for setting the field value
- Triggers "after saving new content" and "after updating existing content"
- appropriate conditions
- Action "Populate a field" => Advanced: Specify the fields value with PHP code
I did not found a way using computed field for generating a select list.
JV
Solution recipe
Jump Menu appears to be the simple solution, in many cases, but if you want the results in the same views page or block rather than to navigate to a node, it is not sufficient.
My needs target the resulting node content to ajax load on the current page.
Part 1 is to create a jump menu block, and disable submit on it by removing the go button.
Part 2 create a second block with exposed filter for node title (or nid)
set to display single item
turn on ajax
use better filters to hide results until filter supplied, (but don't set to required as that will cause required error we don't want)
this also provides default text so block is not hidden.
hide the input filter
Note hide labels and input, but leave section visible for ajax throbber to show.
use visibility:hidden; not display:none; so form accessible to JS
add JS trigger on jump list combo box select, action copy the title to the exposed filter in second block and trigger submit.
Hal Eagar
Software Architect
hal.eagar@door3.com
Views Reference Filter module can do that ?
Hi,
You can use Views Reference Filter module.
1) First, you have to create a views, select entityreference display, configure it as you want (ex.: Display all node from type article)
2) In your the view where you need to have an exposed filter with pre-populated titles nodes, go to Filter criteria section and then choose a field with reference filter.
I use this module to make an exposed filters list with username which have a specific role in another views that listed all my projects node attached to a user. My mistake, i saw that the version is only for D7.
Thanks Tsymi, now i can
Thanks Tsymi, now i can display selected list anything in filter,,
Entity Reference
I was able to create an exposed filter of titles as a dropdown by using the Entity Reference module. You just need to create a seperate view using the Entity Reference display mode giving the items you want to show in the dropdown. Then in your main view in the filter section create a new filter using NID (reference) and select the entity reference view you created in the previous step. This could be used for any entity.
This was for Drupal 7.
Brilliant
I had no idea you could use NID (reference) to do this. Fantastic and thanks bmango!
thanks bmango, now i can show
thanks bmango, now i can show what i want,
Still a great solution, even
Still a great solution, even in Drupal 8+. Thank you so much!
For Drupal 7
For Drupal 7, I found this kind solution
https://stackoverflow.com/questions/3881718/drupal-views-exposed-filter-...
You need to adapt to the entity you wish to handle and adjust the get_value_option as this code does not take the current views filters into account
I reproduce this post here:
You'll need a custom module for that.
I've done this for Drupal 7 this way: create a module, say,
views_more_filters, so you have aviews_more_filters.infofile like this:(file
views_more_filters_handler_filter_author_select.incwill contain our filter handler).A basic
views_more_filters.modulefile:Then define your filter in
views_more_filters.views.inc:Note that we set
author_selectas a machine name of the filter, defined filter handler ('handler' => 'views_more_filters_handler_filter_author_select') and a field we will filter by ('real field' => 'uid').Now we need to implement our filter handler. As our filter functions just like default
views_handler_filter_in_operator, we simply extend its class inviews_more_filters_handler_filter_author_select.incfile:We haven't had to do much here: just populate options array with a list of our users, the rest is handled by parent class.
For further info see:
JV