Please consider making description length limit of 200 characters configurable. Currently it is hardcoded and to change that in a subtheme the whole bootstrap_form_element function has to be copy pasted into subtheme just to change this one value to allow longer tooltips.

It's just a small change to the configuration form (theme/settings.inc):

  // Added to allow auto tooltips for longer descriptions
  $form['javascript']['tooltips']['bootstrap_tooltip_descriptions_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Simple form description length limit'),
    '#description' => t('Form items that contain simple descriptions (no HTML) will be converted into tooltips if description length is smaller than this value.'),
    '#default_value' => theme_get_setting('bootstrap_tooltip_descriptions_length'),
    '#states' => array(
      'visible' => array(
        ':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE),
      ),
    ),
  );

and to the bootstrap_form_element function (theme/system/form-element.func.php):

  // Convert some descriptions to tooltips.
  // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form()
  if (!empty($element['#description'])) {
    $description = $element['#description'];
    if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description) && strlen($description) <= theme_get_setting('bootstrap_tooltip_descriptions_length')) {
      $tooltip = TRUE;
      $attributes['data-toggle'] = 'tooltip';
      $attributes['title'] = $description;
    }
  }

I can prepare a patch if you want but please let me know if you are interested in implementing this at all. The hardcoded value is real PITA here.

Comments

  • Commit 53dc5d3 on 7.x-3.x by Mark Carver:
    Issue #2204689 by Mark Carver | SiliconMind: Make form element...
markhalliwell’s picture

Version: 7.x-3.0 » 8.x-3.x-dev
Assigned: Unassigned » ryan.armstrong
Status: Active » Needs review

  • Commit 53dc5d3 on 7.x-3.x, 8.x-3.x by Mark Carver:
    Issue #2204689 by Mark Carver | SiliconMind: Make form element...

  • Mark Carver committed 53dc5d3 on 8.x-3.x.x
    Issue #2204689 by Mark Carver | SiliconMind: Make form element...
markhalliwell’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
Assigned: ryan.armstrong » Unassigned
Status: Needs review » Closed (fixed)

I'm just moving this back to 7.x. If this needs re-evaluation in 8.x, create a new issue.

shiraz dindar’s picture

Agreed this is a bit of a pain as the only way to override the 200 char limit is to patch bootstrap directly in bootstrap_form_element (as this is not overridable -- see https://www.drupal.org/node/1991102).

There's also a limitation here that long text fields do not yet have their description available to $element in theme_form_element, so they do not get the tooltip even if the other conditions are met.

Here's a patch I did for myself to address both these issues.

Mark, if you're interested to roll this (perhaps with a variable for the max char limit, or perhaps excluding the long text change -- which also requires some CSS to hide the non-tooltip description), lmk and I will alter to make it suitable for contribution.

diff --git a/theme/system/form-element.func.php b/theme/system/form-element.func.php
index 6253653..4be1058 100644
--- a/theme/system/form-element.func.php
+++ b/theme/system/form-element.func.php
@@ -67,9 +67,20 @@ function bootstrap_form_element(&$variables) {
   $tooltip = FALSE;
   // Convert some descriptions to tooltips.
   // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form()
+
+  // Mukurtu patch -- use tooltips for (almost) *all* form field descriptions:
+  // 1. Do not limit to only descriptions under 200 chars
+  // 2. For text area fields, the description is not yet available in $element, so load it from the field instance and use that.
+  // 3. We are still respecting the markup condition (description === strip_tags($description)) because jquery-ui tooltips can't show markup
   if (!empty($element['#description'])) {
     $description = $element['#description'];
-    if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description) && strlen($description) <= 200) {
+  }
+  elseif ($element['#type'] == 'textarea') {
+    $textfield = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
+    $description = $textfield['description'];
+  }
+  if ($description) {
+    if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description)) {
       $tooltip = TRUE;
       $attributes['data-toggle'] = 'tooltip';
       $attributes['title'] = $description;
markhalliwell’s picture

I already committed a fix in #1.

shiraz dindar’s picture

Oh sorry I missed that... just now noticing the big gap in release dates for the dev and stable releases. Is a stable release due anytime soon? Just deciding whether to switch to dev or wait.

markhalliwell’s picture

Try upgrading to beta2 first, I'm looking for people to test upgradability. Make sure to read the release notes. If you encounter any issue, please create a new issue.