Hello,
I have a views exposed filter 'search field', and i want add the html5 'placeholder' (with the name="Gemeente") attribuut in the search field, but where can i find the function of this search-field?
And how can I override that?
I will do this on my site http://www.market-locator.com/. The theme on this site is a omega_subtheme.
It's my first time to try developing/overriding a function, but I don't know where to find the functions for exposed filter?
I think to find functions install Devel and place the functions in template.php? Is this right?
Is there a good tutorial to learn the basics how overriding functions?
Christophe
Comments
Its not real clear which form
Its not real clear which form field you are talking about, but all forms are just that, forms, so you can use hook_form_alter() to modify most forms.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Jeff, Is there a good
Jeff,
Is there a good tutorial how can I add the placeholder-attribute on the input field for my exposed filter?
The View-name i want to theme the exposed filter is 'search-results' and the name of the input-field is 'title'.
Is there a good tutorial of hook_form_alter() for theming forms?
Hope you can help me?
Any luck with finding a
Any luck with finding a tutorial for adding the placeholder-attribute on the input field?
I Found how to make a custom module, but...
But how can I add a extra attribute? In the code above, i try to add the 'placeholder'-atribute to the inputfield 'title' but it don't work!
Its hard for me to say
Its hard for me to say without being able to see the form array, i.e the output of dsm($form)
placeholder is an attribute.
something like this
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
It works perfect
Thx!
Clarifcation...
Just to clarify, here is the complete working code:
## Note: The above code is fictitious. Any resemblance to real or actual working code is purely coincidental.
This worked for me
Thanks for posting this code, it worked perfectly for me. Just to clarify, the "title" is the name of the exposed filter, in my case, mine was "combine" (Can be found by right-clicking the form on firefox or google chrome and clicking "inspect element"). Also,
dsm($form)
produced errors so i removed it.Also, i used this code in my template.php file so the function can be adjusted to:
function yourtheme_form_alter(&$form, &$form_state, $form_id)
.... change "yourtheme" to the name of your theme.Hi, thank you for this code!
Hi, thank you for this code! I havent got it working yet, but still...thank you! I'm trying to find the "name of the exposed filter." I see form id, section id, bunch of classes. I'm not sure what "name" i'm looking for :) Its an exposed search filter i'm trying to identify. Where did your "combine" come from?
Update: Got it!
Thank you again!
This is kinda hidden. Open the filter and at the bottom there's a "more" fieldset. Expand and there is "Filter identifier."
Hi, the module code worked
Hi, the module code worked for most fields for me; however, one field it didn't work on is a "is between" filter field. The field names are field_listprice_value[min] and field_listprice_value[max]. If I use either of those as the field name in the code above, it simply does not show any placeholder. How can I get a placeholder to appear in these fields?
=============edit===============
Found the solution!!! (here: https://www.drupal.org/node/2280069#comment-8844805)
Use hook_form_alter in theme
use following code
It worked for me
Views exposed forms have the
Views exposed forms have the $form_id of 'views_exposed_form', so you may also need to filter by the View and Display Id.
This worked for me.
Awesome!
Thanks for posting this since I'm not a huge fan of JS used to do something that is supposed to be HTML5!
Here's a mod and improvement to your code. It essentially pulls the label directly from views that you have set, uses that, and then it removes the label ;). ALSO it loops through any fields that you have set and carries this out so it eleviates the issue of having to find the proper field.
it worked for me. thanks
it worked for me. thanks
To add to this topic, I also
To add to this topic, I also had a views exposed filter 'search field' that I wanted default input to read something like 'Search...'. I wanted this default 'Search...' text to clear when user clicked into the search box to perform search. Here's tips on how to accomplish:
Also I never did actually end up using HOOK_form_alter. I just set that in the view's exposed filter settings for "Value".
@vrwired solution Worked for me.
@vrwired Thank you for the detailed explanation. Was able to achieve the necessary result.
back to hook_form_alter
I later updated my code back to using hook_form_alter as another module had conflict with the javascript I previously posted. Nonetheless, to help anyone else this is how I did it:
1) Go to your theme and find template.php
2) Turn on devel module.
3) Insert the following function and determine what your exposed filter is named (be sure to replace [theme_name] and clear drupal cache):
4) After you find the name of your exposed filter from dpm($form) output, you can replace 'search_api_views_main' and should work for you.
I like this solution better anyway as it uses the HTML5 placeholder attribute.
Front end solution
I ended up using a bit o jQuery to make use of the label text as a placeholder.
This is the code:
And just hide the original label using css.
date_popup_process_alter() overriding #default_value first
I tried to get this to work a million ways (Drupal 7 in 2017) and this is what finally worked for me:
It wouldn't work without overriding the #default_value first, as I guess it did not let the placeholder show.
Lifesaver
https://www.drupal.org/project/form_placeholder