Hi,
I'm trying to add additional exposed filter fields to a view via my module.
I've added a form_alter hook to my module with the following code:
if ($form_id == 'views_exposed_form') {
$form['recent_event_type'] =
array('#type' => 'select', '#options' => array(0 => t(''), 3 => 'Long', -3 => 'Short'),
'#default_value' => 0,
'#title' => t('Recent Event'),
'#weight' => -2,
);

$form['recent_event_date'] =
array('#type' => 'select', '#options' => array(0 => t(''), 1 => 'Last Day', 3 => 'Last 3 Days', 7 => 'Last Week'),
'#default_value' => 0,
'#title' => t('Event Date'),
'#weight' => -1,
);

The fields are added fine to the view page but the problem is that they are not in the same row - that is, the first field is added to the row with the other exposed filters (defined via Views interface) but the 2nd field is added to a row below - just under the previous field and the Submit button is pushed to another row lower - again directly below (not aligned to the left).

Also, I've seen using Themer-Info (devel) that when I go over one of those 2 new fields or the Submit button they are all being marked with the red rectangle [from themer] as the 'regular' exposed fields are being marked one at a time.

Looking at the generated html I see that there is a div with class 'views-exposed-widget' around each of the 'regular' exposed filters and than a div views-exposed-widget begins before my first added filter and closes after the submit button.

What am I doing wrong?
Thanks.

Comments

duckzland’s picture

you can try to do :

drupal_set_message('<pre>' . print_r($form, TRUE) . '</pre>');

in the hook_form_alter to see all the $form array structure for determining what is missing.

For now, I think your additional $form array is missing the '
#theme' key, that is why in the generated html you are missing div with certain classes.

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

amirn’s picture

I tried adding a #theme (theme_select ) but it didnt change anything. I looked at the $form with dsm() and the 'regular' exposed filters do not have a #theme in their definition.
this is the 'regular' expose filter:
field_info_country_value_many_to_one (Array, 5 elements)
* #type (String, 6 characters ) select
* #options (Array, 3 elements)
o All (String, 5 characters )
o USA (String, 3 characters ) USA
o Canada (String, 6 characters ) Israel
* #default_value (String, 3 characters ) All
* #size (NULL)
* #description (String, 0 characters )

And this is the added one:
recent_event_type (Array, 6 elements)
* #type (String, 6 characters ) select
* #options (Array, 3 elements)
o 0 (String, 5 characters )
o 3 (String, 4 characters ) Long
o -3 (String, 5 characters ) Short
* #default_value (Integer) 0
* #title (String, 12 characters ) Recent Event
* #weight (Integer) -2
* #size (NULL)
* #description (String, 0 characters )

There is something in the $form that I'm not sure what it is: the #info field - it containt the 'regular' exposed filters with the format:
#info (Array, 3 elements)
...
* filter-field_info_country_value_many_to_one (Array, 3 elements)
o operator (String, 39 characters ) field_info_country_value_many_to_one_op
o value (String, 36 characters ) field_info_country_value_many_to_one
o label (String, 7 characters ) Country
There are no #info entries for my added filters.

Any ideas?
Thanks.

duckzland’s picture

it should be some key referring to "theme" key, otherwise views template system wont work as the html portion of the form is build from template not from form arrays.

you probably should print_r the #info array to see what is the array about.

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

amirn’s picture

added:

$form['#info']['recent_event_type'] = array('operator' => 'dummy_op1' , 'value' => 'recent_event_type' , 'label' => 'Event Type');
$form['#info']['recent_event_date'] = array('operator' => 'dummy_op2' , 'value' => 'recent_event_date' , 'label' => 'Event Date');

and now the items are magically inline...
however I've no idea what I did.. and I've used operator with dummy values.