views:

129

answers:

2

I'm using the Ubercart car and I would like to replace the input field to specify the product quantities with a dropdown box.

In this way, customers don't have to type the number of items they want to buy but they can just select an item in the dropdown popup: http://dl.dropbox.com/u/72686/dropdown.png

How can I replace it ?

Thanks

+1  A: 

You'll have to go into the code and change the form-array that is used for a product-ordering (set type to 'select' and set value to an array of values/labels). However if you don't want to touch the original code, you could:

1) Overwrite with a module using hook_form_alter()

2) Override with jQuery by creating a select-list and hiding the standard input then put the select list's value in the hidden input field on change. Example:

$('select#price').change(function() {
   var price = $('option:selected', this).value();
   $('input#price').val(price);
});
Rakward
So, in both cases, I need to use hook_form_alter to replace with / add a select-list, right ?
Patrick
in the first case yes, in the second case you have to use jQuery. Are you more experienced with jQuery or PHP?
Rakward
I've changed the form with PHP. However this is not exactly what I want. See what I got now: (1) and what I would like have instead (2). [1] http://dl.dropbox.com/u/72686/now.png [2] http://dl.dropbox.com/u/72686/later.png
Patrick
I dunno how to call it. It is not just a dropdown list. It is a drowdown button with a popup list.
Patrick
A: 

You can try this in hook_form_alter().

if ($form_id == 'cart form') {
   $x = 0;
   $options = array();
   while ($x < 50) {
      $options[$x] = $x;
      $x++;
   }

   $form['quantity element']['#type'] = 'select';
   $form['quantity element']['#options'] = $options;
}

I did this off the top of my head, but it should work.

Kevin

related questions