Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you create a "datetime" form element via Form API, you will get doubled pre- and suffix.
$form['datetime'] => [
'#type' => 'datetime',
'#suffix' => 'Suffix',
'#prefix' => 'Prefix',
];
I don't know if it relates to
https://www.drupal.org/node/2346893
and if it is datetime theme specific. (its theme functions)
This might occur on other fields too.
Comments
Comment #2
hussainwebCan you give an example output? What is the HTML that you see?
Comment #3
seppelM CreditAttribution: seppelM commentedThats the output.
Both get added outside and inside the container.
Comment #4
seppelM CreditAttribution: seppelM commentedComment #5
TR CreditAttribution: TR commentedConfirmed as a bug. It's even worse if you include a #title because then one of the prefixes is displayed before the title and the other one is displayed after the title.
(I'm pretty sure this has nothing to do with the ajax markup problem cited in the original post.)
There are a number of other issues with the markup here. First is that the #title is displayed as an <h4> instead of as part of the <label> as it is with other form elements. This makes styling of form elements inconsistent. Second, the #title is placed OUTSIDE of the
<div class="form-item ..."
instead of inside, which means .form-item isn't a good selector for the entire element. Again, this is not consistent with what any of the other form elements does.Here is a real use case where I added the prefix and suffix to see what would happen:
And here is the markup:
Using paragraph tags instead of divs it's stranger - note it creates BOTH open and close paragraph tags for the TWO prefixes, then BOTH open and closed tags for the TWO suffixes (but notice the suffix doesn't get the class="bug" ...):
EDIT: I had to edit this issue to make it readable again; some HTML tags inside <?php code block in this post disappeared due to #2725111: < within <?php is not escaped for codefilter_prism.
Comment #10
tacituseu CreditAttribution: tacituseu commentedEven though this issue is earlier, closing in favor of #2783617: Datetime FAPI element type duplicates #prefix and #suffix as it has a patch.
Comment #11
TR CreditAttribution: TR commented@tacituseu: I would appreciate it if, before you close an issue, you check to make sure it really is addressed by the newer issue.
My comments from 18 months ago are NOT all addressed by the patch in #2783617: Datetime FAPI element type duplicates #prefix and #suffix. So now I have to re-create the work I did 18 months ago and re-post in that issue, where they're going to tell me that the markup problems are not part of the datetime.module component, they belong in the FAPI queue or the markup component (which is why I did not put this issue into the datetime.module queue, btw ...). Then I'm going to have to open a new issue which is essentially the same as this, but two years newer, in hopes that someone will take a look at this.
That's progress?
Comment #12
tacituseu CreditAttribution: tacituseu commented@TR: I suspect the reason it didn't get the attention from the maintainer is because it didn't have proper component assigned, FAPI/markup is just too generic.
They look the same to me, the other one has comments from @mpdonadio, and still is at needs work
because not all issues were addressed, feel free to reopen if you feel strongly about it.