So right now we have this function:

function twitter_bootstrap_form_element(&$variables) {

   ...

  // Add bootstrap class
  $attributes['class'] = array('control-group');

If you have a .form-inline form, you may want the control group to wrap around multiple elements.

I suggest we add a possible override to the form array (i.e. #nowrap => true) which would stop twitter_bootstrap from adding this class.

i.e.

  $attributes['class'] = array();
  if (!isset($element['#no_wrap'])) {
    $attributes['class'][] = 'control-group';
  }

Comments

nagiek’s picture

Also, we should put the same override when adding <div class="controls">.

Replace

  $output .= '<div class="controls">';

with

  $output .= !isset($element['#no_wrap']) ? '<div class="controls">' : '';
nagiek’s picture

And the last point to make this work is the wrapper divs (like .form-type-*) have to be modified

i.e.

.form-inline .form-type-textfield {
  display: inline-block;
  margin-bottom: 0;  
}
davidn’s picture

The following function can than be used to make an inline form out of an existing form arrray:

/**
 * Makes a form a bootstrap inline form.
 *
 * All children retreive #no_wrap => TRUE.
 *
 * @param array $elements
 *   The form array to make an inline form.
 * @param boolean $title_placeholder
 *   If titles should be displayed as placeholders.
 * @return string|boolean
 *   The updated form.
 */
function twitter_bootstrap_form_inline($elements, $title_placeholder = TRUE){
  // Add class form-inline to form element.
  if (!empty($elements['#type']) && $elements['#type'] == 'form')
    $elements['#attributes']['class'][] = 'form-inline';
  // #no_wrap => TRUE for all children.
  $children = element_children($elements, TRUE);
  if (empty($children)) 
    return $elements;
  foreach ($children as $key) {
    $elements[$key] = twitter_bootstrap_form_inline($elements[$key]);
    $elements[$key]['#no_wrap'] = TRUE;
    // Set placeholder.
    if ($title_placeholder && !empty($elements[$key]['#title'])) {
      $elements[$key]['#title_display'] = 'invisible';
      $elements[$key]['#attributes']['placeholder'] = $elements[$key]['#title'];
    }
  }
  return $elements;
}

By the way. I prefer to totally remove the div wrappers when #no_wrap is set. I haven't counter any problem with the missing classes till now!

andregriffin’s picture

Project: Twitter's Bootstrap » Bootstrap Framework
andregriffin’s picture

Project: Bootstrap Framework » Twitter's Bootstrap
natted’s picture

Project: Twitter's Bootstrap » Bootstrap
natted’s picture

Issue summary: View changes

Typo

markhalliwell’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Scripted response: This issue has been closed while cleaning up the issue queue. This has likely already been addressed in 7.x-3.x. If it has not, please create a new issue describing the exact issue with that version. The 7.x-2.x branch currently only receives security fixes.