No Code Attached Yet
avatar jjbongio
jjbongio
27 Oct 2022

Haven't converted to J4 yet because of an extension dependency, but wanted to report this in case it was still an issue.

getLabel in note.php field last line is
return '</div><div ' . $class . '>' . implode('', $html);
should be
return '<div ' . $class . '>' . implode('', $html) . '</div>';

Steps to reproduce the issue

Use the note type in any form in an admin extension. The incorrect </div> will close
the main container.

Expected result

Actual result

System information (as much as possible)

Additional comments

avatar jjbongio jjbongio - open - 27 Oct 2022
avatar jjbongio jjbongio - change - 27 Oct 2022
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 27 Oct 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Oct 2022
avatar richard67
richard67 - comment - 27 Oct 2022

@jjbongio If you check the description of your issue on GitHub you will see that the markup is not visible, e.g. the <div>. Markup or code needs to be quoted with ` to be visible here. I could correct that for you, but I thought it's better if I let you know first. Let me know if you have some questions or if I shall change the description for you.

avatar jjbongio
jjbongio - comment - 27 Oct 2022

Thank you for pointing this out. I would appreciate your updating it, as I'm not completely clear on how to escape it properly.

avatar richard67 richard67 - change - 27 Oct 2022
The description was changed
avatar richard67 richard67 - edited - 27 Oct 2022
avatar richard67
richard67 - comment - 27 Oct 2022

@jjbongio Done. If you edit the description you will see how I have done it.

avatar jjbongio
jjbongio - comment - 27 Oct 2022

Got it. Thanks muchly.

avatar ReLater
ReLater - comment - 28 Oct 2022

I checked that issue yesterday (TBH, not too intensive) but couldn't find any unclosed <div> in the source code of checked pages. For example:

grafik

But I gave up to find the code place where the </div> is added.

avatar ReLater
ReLater - comment - 28 Oct 2022

The same with a close="true". No invalid HTML.

grafik

avatar ReLater
ReLater - comment - 28 Oct 2022

This issue seems to be Joomla 3. I have tested with Joomla 4. But in Joomla 4 it's the same PHP code and no invalid HTML:

return '</div><div ' . $class . '>' . implode('', $html);

avatar jjbongio
jjbongio - comment - 28 Oct 2022

I may not have explained it well. The generated HTML is perfectly valid, but it does the wrong thing. The </div> closes an outer div and the <div> starts a new div at the same level as the outer div. What it should do is return a div with the label code in it and close it.
If this isn't clear, I can code an example.

avatar ReLater
ReLater - comment - 29 Oct 2022

I would say that's on purpose. Because in note fields the label is just a H4 headline and not a real field label. The same for the description.

Yes, the empty divs are not nice in Joomla 3 but I think it would be bigger effort to put the label (= headline) into a div with class="control-label" than to leave it as it is because you have to change CSS, too, or things like that.

As always: I don't have to decide that. But that's for sure not a security issue (or a bug). Joomla 3 is locked for other fixes than these.

Examples from Joomla 3.10.11:

grafik

grafik

grafik

avatar billyroberts11
billyroberts11 - comment - 2 Nov 2022

This issue is likely to be related to Joomla 3's fault.

avatar Fedik
Fedik - comment - 2 Nov 2022

That on purpose as @ReLater already noted. This hacky way works for years, and unlikely will be changed for Joomla 3.10.
However would be nice if someone find a less hacky way to render this field in Joomla 4

avatar jjbongio jjbongio - change - 3 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-03 02:40:04
Closed_By jjbongio
avatar jjbongio jjbongio - close - 3 Nov 2022
avatar jjbongio
jjbongio - comment - 3 Nov 2022

I'm not sure I'm describing this correctly (I'm new to the forum, so be patient).
I have a field defined in a form as

<field
name="note1"
type="note"
label="Some Label"
/>

When I use this form in the backend, the returned label is
</div><h4>Some Label<div>

which closes out the containing div.

avatar jjbongio jjbongio - change - 3 Nov 2022
Status Closed New
Closed_Date 2022-11-03 02:40:04
Closed_By jjbongio
avatar jjbongio jjbongio - reopen - 3 Nov 2022
avatar Fedik
Fedik - comment - 3 Nov 2022

@jjbongio you described it correctly.
This </div><h4>Some Label<div> is on purpose.

Look the layout file joomla.form.renderfield, it render field label and input, like:

<div class="control-group">
  <div class="control-label"><?php echo $label; ?></div>
  <div class="controls"><?php echo $input; ?></div>
</div>

Now, because we do not want that Note label be inside <div class="control-label">, we do return '</div><div ' . $class . '>' . implode('', $html); in the Note field label, and in result we get:

<div class="control-group">
  <div class="control-label">
    </div><h4>Some Label</h4><div>
  </div>
  <div class="controls"><?php echo $input; ?></div>
</div>

As you can see result markup is correct, even when $field->label return incorect one.

When I use this form in the backend, the returned label is

You probably use it as echo $field->label, try use it as echo $form->renderField($field).
Or add extra wrapper for a Note field on your own: echo '<div>' . $field->label . '</div>';
In this case your form will not be broken.

avatar chmst
chmst - comment - 3 Nov 2022

@jjbongio I have marked your code so that it is visible. I am wondering how you check the source code of your site?

I have added your code in user config.xml and get this:
If your structure is destroyed then the error could be somewhere on your site and produce a side effect here.

grafik

avatar brianteeman
brianteeman - comment - 3 Nov 2022

image

avatar Fedik
Fedik - comment - 3 Nov 2022

I am wondering how you check the source code of your site?

The Inspector not a reliable source, it shows rendered result (by browser) not real markup (from server).
Because Browser may magicaly fix a broken markup, it will looks correct in the Inspector.

And it possible to get a broken markup with Note field. Check my previus comment for details.
When rendering on your own (I mean without use of $form->renderField($field)), example:

<p><?php echo $field->label; ?></p>

It will produce:

<p></div><h4>Some Label</h4><div></p>

It does not happens in core forms, but easily in 3rd extensions in custom form.

avatar jjbongio
jjbongio - comment - 3 Nov 2022

@Fedik Yes, it is a custom form, and I am using $field->label

avatar jjbongio jjbongio - change - 4 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-04 01:21:20
Closed_By jjbongio
avatar jjbongio jjbongio - close - 4 Nov 2022
avatar jjbongio
jjbongio - comment - 4 Nov 2022

I was looping through $form->getFieldSet() as $field and echoing $field->label and then $field->input
When I changed it to echo $field->renderField (), it worked nicely without closing the parent div.

Thanks to all for your comments.

avatar Baliar93
Baliar93 - comment - 30 May 2023

Spam with external link faking a Joomla site removed.

Add a Comment

Login with GitHub to post a comment