0

I'm working on a select list content type which is essentially check boxes with words on one side. The issue appears to be that the html tags I put in that are allowed are stripped out when I go to save. I checked both text formats and it appears that all html is allowed, Any idea where I can look to see why the html is stripped out of the list?

Edit: The allowed values list has tags and I also am testing with a tag, when I save the settings and refresh the view that has these check boxes and text, the text doesn't change according to the html assigned to it. I've looked and text formats (WYSIWYG, HTML, and plain text) do not have the "limit allowed HTML tags" check box checked. So I am not sure why the tags are being filtered out any ideas? thank you.

  • Welcome to Drupal Answers. Please note, that Drupal is a very complex CMS with various ways to achieve your use cases. It's almost impossible for us to guess how you are doing things from just three sentences with such less information. In order to getting a good answer, please describe brief, but with enough details what you did, why you did it, the expected/intended results and what isn't working as expected. Also, consider adding relevant code snippets. – Mario Steinitz Aug 7 '18 at 13:31
  • Just to clarify: Even your edit leaves too much room for guessing. So I guess, you are trying to add a select element to your output by actually coding it into a text field with rich text editor? – Mario Steinitz Aug 7 '18 at 14:09
  • I'm sorry I wasn't clear (I'm still working on being clear) The field type is a List(text) so the way the Drupal site is set up this will be check boxes. When I do for Example: This is|<i>Example</i> Text , you need the | and the tag type for it to work but when I save the field and refresh the view with this field the <i> tag doesn't appear to have worked, or any other tag. – Paul Aug 7 '18 at 14:13
  • You might be able to do this with an allowed_values_callback. – mradcliffe Aug 10 '18 at 0:07
0

According to your question comments, you are trying to create a form with an options list element using the core select element widget.

This widget is intended for creating select lists. Markup within select list options is considered invalid HTML. That's why the select options widget has a sanitizing function for its option labels, namely OptionsSelectWidget::sanitizeLabel(). This sanitizer is used on each widget settings form submit and cleans your labels from any HTML.

If you really require an options element with HTML in the option labels, you have three choices:

(1) Choose another widget type for the list field that supports HTML markup natively. Obviously you choose the select widget. Choosing checkboxes or radios as widget type in the "manage form view" tab will use the less restrictive satitizing function of the the abstract OptionsWidgetBase class.

(2) If you need an entirely unfiltered list, create a custom field widget for your list field. Make sure to also implement a form element different from select that supports HTML in its labels.

(3) Leave the sanitized labels in the Core widget configuration as is and use hook_field_widget_form_alter() to add your markup to the labels of the element you intend to replace the Core elements with.

  • Thank you for this, I'm going to see what I can make work. – Paul Aug 9 '18 at 13:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.