Remove escaped HTML Tags from Reference View

Created on 8 June 2021, about 3 years ago
Updated 16 April 2024, 2 months ago

Problem/Motivation

When using a Reference View to display autocomplete results, the HTML tags are escaped and therefore display as string text instead of HTML. This prevents the ability to create custom formatted autocomplete results.

Steps to reproduce

Create a reference view
Create an entity reference field and select the reference view as reference type.
On form settings select Select2 with Autocomplete checkbox
The autocomplete result will contain Escaped HTML tags

Proposed resolution

Remove the escaped function to allow the rendering of HTML Tags.

🐛 Bug report
Status

RTBC

Version

1.13

Component

Miscellaneous

Created by

🇺🇸United States chucksimply

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇷Greece GiorgosK Chios, Greece 🇬🇷

    Workaround: If one updates all view fields and changes in the style section

    Customize field and label wrapper HTML
    Customize label HTML
    Customize field HTML

    and sets the Element to none, no HTML is passed to select2 and there is no need for this patch.

  • Status changed to Fixed about 1 year ago
  • 🇩🇪Germany chr.fritsch 🇩🇪🇪🇺🌍

    I think the workaround from @GiorgosK is fine. If you think select2 should do some additional work, feel free to reopen the issue.

  • Status changed to Closed: works as designed about 1 year ago
  • 🇬🇷Greece GiorgosK Chios, Greece 🇬🇷

    So technically this should be works as designed

  • 🇺🇦Ukraine Kostiantyn

    @tuuuukka When I apply the patch, I encounter the error "TypeError: undefined is not an object (evaluating 'drupalSettings.select2.htmlAsText')". The error disappears when I set the configuration for the field, but it's not very convenient to set these settings for every field, even for those where these values are not needed.

  • 🇩🇪Germany Duwid

    I'm working on a case where I need to keep and render the html from select2 results, instead of removing it as described in @GiorgosK workaround. Therefore I will open this issue again, because I think the implemented solution from @Tuuuukka is a great improvement. I just found a little issue in select2.js:
    if (drupalSettings.select2.htmlAsText === false) {
    htmlAsText is int 0, so it should be:
    if (drupalSettings.select2.htmlAsText === 0) {

  • Status changed to Needs review 4 months ago
  • 🇺🇦Ukraine Kostiantyn

    @Duwid, thank you for your improvement, I am testing it right now.

  • Status changed to RTBC 4 months ago
  • 🇩🇪Germany Duwid

    This patch robustifys implementation if htmlAsText is not available because select2 widget is programmatically implemented via form api. For example this is the case social group invite module.

Production build 0.69.0 2024