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.
By default the search_block_form label is hidden, so I used hook_form_alter to override the setting - $form['search_block_form']['#title_display'] = 'before';
Class 'compact-form' is added to the form but class 'compact-form-label' is not added to the label and 'compact-form-field' is not added to input.
Comment | File | Size | Author |
---|---|---|---|
#5 | compact_forms-search_input_type-154137.patch | 604 bytes | cameron prince |
Comments
Comment #1
Dentorat CreditAttribution: Dentorat commentedAny follow up information on this, I am having the same issue. Thanks
-Tomas
Comment #2
BWPanda CreditAttribution: BWPanda commentedSee if the patch here helps: #1890816: Automatically show hidden labels
Comment #3
Baysaa CreditAttribution: Baysaa commentedHaving exact same issue as the OP describes. compact-form class is added to the form but the label and input don't get the correct classes added to them.
I've used the following hook_form_alter to show the label.
And added 'search-block-form' into the CSS id's of compact forms.
Compact forms version: 7.x-1.0
Drupal version: 7.17
JS console shows 0 JS errors.
My label doesn't have element-invisible class so the patch in #2 is non-applicable to my case, nor the OP's.
The weird thing is I have another website on the same local dev server, and that website has the exact same module version and drupal version, and the compact forms works on there. I'm scratching my head trying to figure out why.
------
Edit:
As mentioned before I have another website with working compacted search block form. The only difference I can see between them is the one that's NOT working has an input type="search" while the one working has input type="text". I've inspected the compact_forms.js file and it's indeed checking if $field.is('input:text,input:password,textarea') so type="search" would not get compacted.
I'm quite positive it's theme related, as the one that has type="text" is Omega xhtml sub theme. And the one that's not working is using AdaptiveTheme. I've found the following preprocess in adaptivetheme's at_core (file: sites/all/themes/adaptivetheme/at_core/inc/preprocess.inc line 790):
Which changes the type from "text" to "search". If you use the same preprocess in your sub-theme and reverse the change it should work:
OR you can always patch compact_forms.js line 23 to:
if (!$field.length || !$field.is('input:text,input:password,textarea,input[type=search]')) {
Which equally works.
Comment #4
rafayama CreditAttribution: rafayama commentedI used the search block form alter to remove the 'element-invisible' class, but the compact forms is not applying 'compact-form-label' and 'compact-form-field compact-form' classes to label and field in internal pages only. If I remove with jquery, it also does not work in internal pages. In the home page, it works fine (and yes, the form has the same ID).
I'm using zen theme, core 7.19, and compact forms 7.x-1.0. By the way, my search field type is 'text'.
[FIXED]
Comment #5
cameron prince CreditAttribution: cameron prince commentedHere is a patch for the fix posted in #3 (compact_forms.js modification).