Vote up!
Vote down!

Changing default select list to radio buttons impossible?


Is it true that the default select list for selecting products references by product reference in a single display cannot be changed to radio buttons?

I was able to change additional attributes to radio buttons (color, size etc) but not the default one.

For instance, if you set up 3 products and you add a new node with a product reference field referring to the 3 products, your product node will get the default select list for selecting product 1, product 2 or product 3. I am unable to change this select list to radio buttons.

Is this indeed impossible?

Asked by: Sem
on May 22, 2013

2 Answers

Vote up!
Vote down!

Did you check via hook_form_alter() or hook_form_FORM_ID_alter()?

Something like the following only gives you handling for 1 case (when all product references are of the same "type"):

 * Implements hook_form_alter().
function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if (
strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
$form['product_id']['#type'] = 'radios';

But note this (from Commerce's related source code):

// Note that this element by default is a select list, so its #options
// are not sanitized here. Sanitization will occur in a check_plain() in
// the function form_select_options(). If you alter this element to
// another #type, such as 'radios', you are also responsible for looping
// over its #options array and sanitizing the values.

However not sure it is affecting Drupal 7 (I'd tend to believe Commerce though): http://drupal.org/node/28984

Answer by: Favio Manriquez
Posted: May 26, 2013
Vote up!
Vote down!

Thanks favrik!

However, I was looking for an option without code. I know that with some coding this could be accomplished but was wondering if it is possible without the need of writing custom code.

I am trying to bend my needs around the possibilities of Drupal in stead of the other way around.

Answer by: Sem
Posted: Jun 3, 2013