in my language file i have these labels
COM_MPROWBUILDER_TITLE_SPEAKER_TYPE = "Select a type"
COM_MPROWBUILDER_TITLE_SPEAKER = "Speaker"
COM_MPROWBUILDER_TITLE_MODERATOR = "Moderator"
COM_MPROWBUILDER_TITLE_SPEAKER_MODERATOR = "Speaker/Moderator"
this is my form file
<field name="moderator"
filter="safehtml" type="radio" default="0"
required="true"
class="btn-group"
label="COM_MPROWBUILDER_TITLE_SPEAKER_TYPE"
>
<option value="1">COM_MPROWBUILDER_TITLE_MODERATOR</option>
<option value="0">COM_MPROWBUILDER_TITLE_SPEAKER</option>
<option value="2">COM_MPROWBUILDER_TITLE_SPEAKER_MODERATOR</option>
</field>
this is what i expect as result:
Joomla 3.9.14
phph 7.3
This behaviour happens only with option labels
infact the label "COM_MPROWBUILDER_TITLE_SPEAKER_TYPE" is rendered correctly.
It seems a parsing mistake.
To avoid this i changed the label in COM_MPROWBUILDER_TITLE_SPEAKERMODERATOR so it works
Labels |
Added:
?
|
Title |
|
I've found the resaon for your special case:
Your field name is "moderator".
In JFormField::getOptions()
your label COM_MPROWBUILDER_TITLE_SPEAKER
is sent through
Methode Text::alt()
See: https://github.com/joomla/joomla-cms/blob/3.9.14/libraries/joomla/form/fields/list.php#L158
which means in your case
JText::alt('COM_MPROWBUILDER_TITLE_SPEAKER', 'moderator')
These lines lead to the error:
https://github.com/joomla/joomla-cms/blob/3.9.14/libraries/src/Language/Text.php#L163-L166
which means in your case
if (Factory::getLanguage()->hasKey('COM_MPROWBUILDER_TITLE_SPEAKER' . '_' . 'Moderator'))
{
$string .= '_' . 'Moderator';
}
COM_MPROWBUILDER_TITLE_SPEAKER
becomes COM_MPROWBUILDER_TITLE_SPEAKER_MODERATOR
because there also exists a key COM_MPROWBUILDER_TITLE_SPEAKER_MODERATOR
.
All I can say is "strange behavior" but don't know how to solve it ;-)
Labels |
Added:
J3 Issue
|
Nice sleuthing! Looking at the examples in these lines, should $alt
value be field
and not dynamic values? It will fix in this instance, but I don't see a way to solve it either other than document it.
https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Language/Text.php#L148-L149
I don't see a way to solve it either other than document it.
Documentation done: https://docs.joomla.org/Wrongly_rendered_option_labels_in_form_fields_under_some_circumstances
I did not test with Joomla 4. But I think it has the same issue after comparing the relevant classes:
https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Form/Field/ListField.php#L122
Based on the comments above and that this has been documented it should be closed
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-08-23 13:39:22 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
Confirmed. Also with Joomla 3.9.13.
Image is with language debug activated. Strings in "en-GB.override.ini" (administrator).