0

I am trying to set the available currencies programatically like this:

function mymodule_form_alter(&$form, $form_state, $form_id) {
    /** Modify exposed filter views */
    if ($form_id == 'views_exposed_form') {
        $form['field_1hour_currency']['#type'] = 'select';
        $form['field_1hour_currency']['#options'] = array('EUR','USD');
    }
}

But I get An illegal choice has been detected. Please contact the site administrator. error in the view.

How can I set a select list of available currencies in the views exposed filter for a CCK currency field?

Thank you

(using D6, Views 2 and latest CCK Currency)

0
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'myview') {
    // Add our custom All buttons.
    $form['field_1hour_currency']['#type'] = 'select';
    $form['field_1hour_currency']['#options'] = array(
      '' => t('<Any>'),
      'USD' => 'USD',
      'EUR' => 'Euro'
    );
  }
}

The key is to ensure you include the empty option:

'' => t("<Any>")

See http://drupal.org/node/463990

You may want to post this solution on your issue on drupal.org too if it works for you: http://drupal.org/node/1155934 ;)

2
  • thank you! I know it's another question, but just in case you already have a link for that. How can I turn that into drop-down select list? (it is now a multiple select box) – Naoise Golden May 15 '11 at 20:48
  • Answered here – Naoise Golden May 16 '11 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.