Hi there, I'm new to hook_form_alter. I was wondering if anyone could walk me through this.

I have a page set up here, it's an exposed views with a select menu. I'm trying to edit the #size attribute of the select menu. (Make it something like 8.)

So far I have created my module & enabled it. (My module name is dojo.)

The dojo.info file looks like this:

; $Id: dojo.info,v 1.9 2008/04/28 17:54:57 jsudesign Exp $
name = Dojo
description = Places a size option for select form.
dependencies = hierarchical_select
package = Form Elements

My dojo.module file looks like this.

<?php
// $Id$

/**
* @file
* Module to give #size attribute to hierarchical_select module dropdown.
*/

/**
* Implementation of hook_form_alter()
*/

?>

and know I need help, I'm not to sure where to start...
Can someone Please walk me through this?

Thanks, - Justin

Comments

nevets’s picture

Your link does not work but my guess is you can use css to limit the width of the select box.

(And please do not double post, duplicate removed)

hinchcliffe’s picture

Sorry for the double post,

Here's link

http://www.e-techcomputers.com/catalog/ink_finder2

I'm not looking to edit the width. I'm looking to edit the size attribute in the select form with hook_form_alter.
If you need more info you can find it here: http://drupal.org/node/288833

nevets’s picture

I think you will find if you add the following to your themes style.css it will do what you want.

.view view-Ink-finder2 #views-filters select {
width:100px;
}

Just make sure you add it after the rule for #views-filters select (around linf 1423 in style.css ) Size just determines the width in characters. The css while it does it any just about any unit but characters is far easier to implement (no code). Adjust the 100px as needed.

hinchcliffe’s picture

nevets,

I thought that Size would allow my select dropdown to show a limited number of options then create an auto scroll for the rest that are not visible.

I've tried to do this with css, nothing as worked so far.

Example.

<form>
  <select size="2">
    <option> Option 1 </option>
    <option> Option 2 </option>
    <option> Option 3 </option>
    <option> Option 4 </option>
  </select>
</form>

This would only make two options visible in the dropdown, the rest would be scrollable to find. Is this correct?
Source: http://www.cs.tut.fi/~jkorpela/HTML3.2/5.47.html

nevets’s picture

Sorry thinking of the size attribute for a text field, to start with your hook would look like (given your module name is dojo)

function dojo_form_alter($form_id, &$form) {
  if ( $form_id == 'views_filters' ) {
    // Have the form we want, at this point you
   // need to understand how the form is layed out
    // I use the following to figure this out
    drupal_set_message("Form:<pre>" . print_r($form, TRUE) . '</pre>');
  }
}

Hopefully this will get you going.