开发者

Ubercart, replacing quantity input text with a dropdown box

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 do开发者_开发问答n'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


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['qty']['#type'] = 'select';
   $form['qty']['#options'] = $options;
}

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


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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜