Hi, I'm working on a project where several long, formatted text fields were put in place, along with some long, plain text fields. At some point it was decided to remove the WYSIWYG on the formatted fields and only allow "plain text" format. The tooltips are enabled on the theme. The description text on the long, plain fields pops up using tooltips. On the formatted fields, however, the description appears below the field.

To get the formatted fields to put the text into tooltips, I tried to alter the form and add a "data-toggle='tooltip'" attribute to the formatted fields, but that did not work. Do I need to alter the element?

I did not see a similar issue in the queue. Any tips are greatly appreciated. Thanks.

Comments

ccshannon created an issue. See original summary.

Priyadarshini Govinthan’s picture

I could enable the tooltip by adding the code below to my views-view-unformatted--[ViewsMachinename]--[ViewsDisplayname].html.twig

<textarea data-toggle="tooltip" data-placement="top" title="test" >test
</textarea>

In Custom.Js file

(function ($, Drupal) {
	Drupal.behaviors.myBehavior = {
		attach: function (context, settings) {			
			$('[data-toggle=tooltip]').tooltip();			
		}
	};
})(jQuery, Drupal);
Priyadarshini Govinthan’s picture

Status: Active » Needs review
ccshannon’s picture

Thanks @Priyadarshini! This got me to make another attempt.

I thought I had already tried this, but I was able to get it to work using form_alter:

    $helptext = $form['field_my_field']['widget'][0]['#description']->__toString();
    $form['field_my_field']['widget'][0]['#attributes']['data-toggle'] = 'tooltip';
    $form['field_my_field']['widget'][0]['#attributes']['data-original-title'] = $helptext;
    unset($form['field_my_field']['widget'][0]['#description']);

:)

markhalliwell’s picture

Status: Needs review » Closed (works as designed)

Descriptions are automatically converted into tooltips if they meet the certain requirement criteria defined in the theme settings:

https://drupal-bootstrap.org/api/bootstrap/docs!Theme-Settings.md/group/...

You can, however, explicitly force/disable this by manually setting the #smart_description property. An example using the code from above:

$form['field_my_field']['widget'][0]['#smart_description'] = TRUE;
ccshannon’s picture

Thanks, @markcarver. I do have that theme setting enabled, but it did not have any effect on formatted plain-text fields.

Good to know how to do it on the widget. Much appreciated!

-C