Hi,
for a type of content, the numbers of options in a selectBox are determined by Taxonomy Acess Control.
for a particular group the selectBox had only one option.

Is possibile to automatically preselect that value?

thanks

Comments

cpugeniusmv’s picture

This is an issue that extends beyond the scope of TAC (See #180109: Only taxonomy term selected by default when there is only one)

I'm inclined to wait for that issue to be resolved before deciding what to do within TAC.

For my own sites where this issue is a problem, I've create a simple module with the following code:

/**
 * Implementation of hook_form_alter().
 */
function taxonomy_default_form_alter(&$form, $form_state, $form_id) {
  if ($form['taxonomy']) {
    foreach (array_keys($form['taxonomy']) as $vid) {
      if ($form['taxonomy'][$vid]['#required'] && 0 == count($form['taxonomy'][$vid]['#default_value'])) {
        if ($form['taxonomy'][$vid]['#options'][0]) {
          $term_keys = array_keys($form['taxonomy'][$vid]['#options'][0]->option);
          $form['taxonomy'][$vid]['#default_value'] = $term_keys[0];
        }
      }
    }
  }
}

It seems to work.

cpugeniusmv’s picture

I should explain that this code will set the first (or only, if there is just one) item as the default selection (where no default selection exists) for only required fields.

xjm’s picture

Title: SelectBox Auto Selected » Automatically select term when only one term is available

Doesn't look like the patch made it into core for 6.x, so it's probably worth patching in TAC.

xjm’s picture

Marked #208798: upgrade to drupal 5.4 broke something as duplicate of this issue.

xjm’s picture

Issue tags: +TAC UX

Tagging.