Problem/Motivation
While using a "list" field type and adding items to the "Allowed values", there is a list of "Allowed HTML tags in labels".
Any HTML in a label is being stripped out of the label.
This concerns only when the label is displayed, in a form no HTML is allowed inside an <option> tag.
Steps to reproduce
Configure a list field with HTML in the allowed values label and display it.
Proposed resolution
Remaining tasks
- Verify the bug still exists
- Add/modify tests to assert the HTML is being stripped when is displayed inside an
<option>tag and displayed when the label is rendered - Write code that allows HTML when displaying the label
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | interdiff-36_37.txt | 1.75 KB | gauravvvv |
| #37 | 3089983-37.patch | 3.52 KB | gauravvvv |
| #36 | reroll_diff_20-36.txt | 4.52 KB | sahil.goyal |
| #36 | 3089983-36.patch | 2.71 KB | sahil.goyal |
| #34 | html_tags_in_checkbox_labels.png | 5.92 KB | alucinogenado |
Issue fork drupal-3089983
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
greatmatter commentedComment #3
valthebaldBumping target issue, adding tags
Comment #4
fazni commentedComment #5
fazni commented@greatmatter Description is not clear for me, could you please attach the screenshot.
Comment #6
valthebald@fazni please avoid assigning Novice issues (see https://www.drupal.org/node/1319140 for details).
Trying to reproduce the issue (and provide screenshots) could be one possible way to move this issue forward.
Thank you!
Comment #7
fazni commented@valthebald, thank you your feedback is important, I don't know too much about the policy.
I add somthing like that
drupal.org|<b>drupal.org</b>in field allowed HTMLAt level of HTML ( I inspect elements) of select it will be stripped
"<select><option value="drupal.org">drupal.org</option></select>"At level of page (front-end/display) the style(css) of the
<b>tag will be applied.Comment #8
simon peacock commentedI would say this works as intended.

The html is not displayed in the label on the node form (I believe this is correct), but is respected on the front-end.
Comment #9
simon peacock commentedComment #10
.tom commentedWorking on this from Drupalcon Amsterdam
Comment #11
mikkmiggur commentedIt might be still a issue in the node edit form because it might be difficult to separate values when you have multiple values there with different tags. A simple example where is difficult to separate values without HTML in the admin form:

Comment #12
simon peacock commentedI can see this being beneficial. But I have concerns for tags such as the anchor.

This could potentially render the list unusable.
Image tags would also be a problem.
As suggested, we could strip the href from the anchor but with the image we could have a really horrible looking drop down.
I appreciate these are edge cases but I'm concerned we will be introducing the potential for more issues later on.
Comment #13
simon peacock commentedSo it looks like adding html to the `option` tag is invalid mark-up.
As discussed on SO:
can I use html tags in the options for select elements
This make me even more nervous for going against standards outside of Drupal.
I would consider this issue as 'works as expected'.
Comment #14
mikkmiggur commentedWhen HTML tags are showed in the edit view it's much more useful.

An example where tags are displayed and attributes are removed.
Comment #15
sutharsan commentedI fail to see what is there for review. It looks to me that there is a discussion going on and there is neither consensus on the problem nor on the solution.
Please do update the issue summary with the problem and proposed solution.
Comment #17
mohrerao commentedI feel people will rarely use allowed HTML tags for listbox. However since we explicitly mention allowed tags this issue needs to be addressed. I tried adding only image tags and it came up with blank values in the form making it difficult to choose.
We should decide on how we display this in the form. can some UI person help on this
Comment #18
mohrerao commentedAdding UI tag so that some UI expert can suggest alternatives.
Comment #19
darrindeal commentedAs stated in #13, the option tag cannot contain markup.
The issue I see is that the list field type is working as intended but the description is confusing in saying that the label can contain markup. This is the same for the float list and integer list. I suggest that this line in the description is removed.
Comment #20
darrindeal commentedI created the patch to change that I proposed.
Comment #21
tanubansal commentedComment #22
tanubansal commented@greatmatter, @darrindeal : After adding the latest patch provided by @darrindeal, I still can't see the HTML tags are applied.
Is it possible to add the steps to replicate the issue?
Comment #23
mayurjadhav commentedAs mention in the #13 we can not add html tags to options in list field.
@tanubansal #20 patch is to remove the description which was invalid and confusing.
Patch works perfect for me, +1 for RTBC.
Comment #24
greatmatter commented@tanubansal : Yes - the steps are as follows:
Unfortunately, as mentioned in #13, it looks like it's not valid HTML to have tags in an <option> tag, so...yeah, we should probably remove the description.
Comment #25
tanubansal commentedAfter adding patch #20, tested via below mentioned steps :
Add a field of any type, but choose "list"
In the "Field Settings" tab, there is a line of text in the description that says "Allowed HTML tags in labels
Add any of the aforementioned HTML tags as a label
Go to the Edit form for the content type
Observe that the list item has the HTML stripped out.
Description text has been removed and updated
This can be moved to RTBC
Comment #27
abhijith s commentedApplied patch #20 and it works fine.The misleading description is removed after this patch.
Screenshots
before patch:

after patch:

Comment #28
abhijith s commentedComment #29
lauriiiWould be useful if someone could update the issue summary since it took a while for me to figure out what this issue was trying to change.
Tagging for subsystem maintainer review in case they want to provide feedback on the solution.
Comment #32
larowlanI think we should retain the text but clarify that it is only used in display mode, not form mode
Comment #34
alucinogenado commentedI agree that the allowed tags list should be kept, but that a warning should be added to clarify that any tags are stripped from select options as per HTML specification.
However, one clarification: HTML tags are allowed in labels, not only in Display mode but also in Form mode, if the field widget is set to Check boxes/radio buttons.
Comment #36
sahil.goyal commentedRerolling the patch #20 as it does not getting compatible with the current version 10.1.x, so i made it updating the patch and now its applied perfectly. updating the reroll_diff along, And hold it to the NW as #29 suggest.
Comment #37
gauravvvv commentedRemoved unused statements, Attached interdiff for same. please review.
Comment #38
gauravvvv commentedComment #41
rodrigoaguileraUpdated the IS without verifying if the bug still exist.
I think it is still a good novice issue so I will keep it on the list for the mentoring team for Vienna.
The Drupal Contribution Mentoring team is triaging issues for Drupalcon Vienna 2025 and we are reserving this issue for Mentored Contribution during the event.
After 17th of October, this issue returns to being open to all. Thanks!
Comment #43
mradcliffeI am removing the Novice tag from this issue because I am a little confused about what I would be verifying based on the steps to reproduce after trying to follow the issue comments. It is possible that this is Novice, but I think it would need a bit more clarity in the steps to reproduce section of the issue summary based on some of the comments with screenshots.
I’m using this documentation as a source: https://www.drupal.org/community/contributor-guide/task/triage-novice-is...
Comment #44
mayurgajar commentedComment #46
mayurgajar commented