Adding a tooltip to a form element (eg $this->buildTooltipHtml ) displays the tooltip as text in the error message.
The span for the tooltip is copied in the error in a div tag.

CommentFileSizeAuthor
Screenshot from 2017-11-20 12-24-43.png21.08 KBXtal

Comments

Xtal created an issue. See original summary.

Xtal’s picture

Issue summary: View changes
andrewmacpherson’s picture

Status: Active » Postponed (maintainer needs more info)

@Xtal - Where is the buildToolTipHtml() coming from? I don't thing it's part of Drupal 8 core API.

If you can provide some more detail about how you produced the markup specimen in your screenshot, that might help.

Xtal’s picture

You're right, the buildTooltipHTML() is a custom method.

The tool tip return is added to the #title of the $form element after the label.
So I think the inline form error is getting everything in the title value and using that as it's message.
I think what might be best for this is to exclude any elements in HTML tags?

public function buildTooltipHtml($text) {

    $tooltipText = Html::escape($this->t($text));

    return '<span class="tooltip-icon" data-tooltip-text="' . $tooltipText . '"></span>';
  }

The return value is added to the form:

$form['eg']['etc'] = array(
      '#type' => 'radios',
      '#title' => $this->t('label here...') . $this->buildTooltipHtml('Tool tip here.'),
      '#required' => TRUE,
    );
Xtal’s picture

Closing this, it's more an issue with how I am generating a tooltip, it shouldn't really be added to the title value and probably belongs in the #prefix or #suffix.

Thanks

Xtal’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)