0

How can I place Description below Title and above field ?

 $form['term-selection']['autocomplete'] = array(
      '#title' => variable_get('autocomplete_sync_shs_autocomplete_headline',t('Type in directly')),
      '#description' => variable_get('autocomplete_sync_shs_autocomplete_info',t('')),
      '#type' => 'textfield',
      '#autocomplete_path' => 'third-level-auto-suggest/autocomplete-taxonomy-term/'.$field_name.'/'.$entity_type.'/' . $node_type ,
      '#states' => array(
         'disabled' => array(
           ':input[name="widget-selection"]' => array('value' => 1 ),
         ),
      ),
      '#default_value' => $default_autocomplete,
    );

The output I get is enter image description here

1 Answer 1

0

User #after_build at the end of your hook_form_alter.

$form['#after_build'][] = 'MODULE_NAME_move_description_up_after_build';

See below function to move the description in between the title and field.

/**
 * build function
 * @param type $form
 * @param type $form_state
 * @return type
 */
function MODULE_NAME_move_description_up_after_build($form, $form_state) {
  drupal_add_js('jQuery(document).ready(function ($) {
    $("label ~ div.description").each(function(index, element) {
      $(this).insertBefore($(this).prev("input"));
    });
  });', array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));

  return $form;
}

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.