1

We need to make the term reference field select list to have no options because the vocabulary have big number of terms which makes the form loads very slow due to getting the term list from DB and render them.

That field is being updated by ajax so we need it start clean with no DB operation to increase performance and page loads fast.

Implementing: hook_field_attach_form or hook_form_alter

has no effect as we see the form is built.

what we need i to prevent DB reading list.

if($form_id == 'field_ui_field_edit_form'){
      $form['instance']['default_value_widget']['field_brand']['und']['#options'] = array(0 => t('No'));
} 

Above code didn't change any thing in node/add form which still list all brands

Is it posible in drupal?

2
  • did you used devel ?? Commented Oct 16, 2015 at 5:48
  • devel for what, I could print the form array and see what inide Commented Oct 16, 2015 at 15:00

1 Answer 1

0

Try with the following code

function yourmodule_form_alter(&$form, &$form_state, $form_id){
 if($form_id == 'your-edit-form-id'){
   $form['your-select-feild']['#options'] = array();
 }
}

Hope this will help you..

1
  • I don't need resetting the options I need to set to null, if you checked the options you will find it filled Commented Oct 16, 2015 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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