User tests: Successful: Unsuccessful:
J4 version of #23499
It is very common to need to display a unit of measurement/value with a field. Currently there is no way to do this without creating custom layouts for every field and every unit when needed.
This PR adds two new param to every custom field "Suffix" and "Prefix" which allows you to add a unit of measurement (or any other text) to be rendered after/before the value of the field.
The new field is disabled by default so there is no b/c issue
Status | New | ⇒ | Pending |
Category | ⇒ | Administration com_fields Language & Strings Front End |
Labels |
Added:
?
?
|
Can you make it so that there are no spaces between the field value and the prefix/suffix?
There aren't any
There aren't any
I guess the spaces come from either the tab or linebreak in the PHP code (depending if suffix or prefix).
<?php if ($showPrefix == 1) : ?>
<span class="field-prefix"><?php echo htmlentities($prefix, ENT_QUOTES | ENT_IGNORE, 'UTF-8'); ?></span>
<?php endif; ?>
There is whitespace between the ?>
and the <?php
which can cause this.
Also, as mentioned in the other issue, is having the "Show suffix" and "Show prefix" yes/no toggles necessary? Wouldn't be simpler to just have two text fields that would display only if not empty?
I'd second this. Just the remove the yes/no toggle and show the prefix/suffix if something is entered.
So instead of <?php if ($showPrefix == 1) : ?>
do <?php if ($prefix) : ?>
. That would make both the code and the UI simpler.
Or do you see a usecase for the toggle?
Category | Administration com_fields Language & Strings Front End | ⇒ | Administration com_fields Front End |
Labels |
Removed:
J4 Issue
|
Category | Administration com_fields Front End | ⇒ | Administration com_fields Language & Strings Front End |
I see another problem with this approach:
$prefix = Text::plural($field->params->get('prefix'), $value);
$suffix = Text::plural($field->params->get('suffix'), $value);
if the prefix language string for plural needs a suffix like 1st 2nd... this maybe and with a space between prefix and suffix.
Sorry I dont understand your plural comment
I'm not sure if a "decoration" attribute with a place holder wouldn't be better
something like:
DECORATION_1="The %dst floor"
DECORATION_2="The %dnd floor"
DECORATION_3="The %drd floor"
DECORATION_N="The %dth floor"
$decoration = Text::plural($field->params->get('decoration'), $value);
And replaces the echo $value completely
How is that not covered by passing this through the Text::Plural
already?
1st, 2nd, 3rd is impossible to do with Text::plural. Because it's not plural forms were talking here. Plurals forms are defined per language and eg in english you only have two forms. It's either plural or singular. So afaik you can't do a "3rd".
1st, 2nd, 3rd is impossible to do with Text::plural. Because it's not plural forms were talking here. Plurals forms are defined per language and eg in english you only have two forms. It's either plural or singular. So afaik you can't do a "3rd".
what a mess...
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-04-23 10:36:53 |
Closed_By | ⇒ | wilsonge |
Thanks
I think this is good enough for now. As Harald has pointed out it doesn't cover every case. But we can work on that if there's demand. I think it's useful enough as it is now.
Thanks!
Nice :)
Can you make it so that there are no spaces between the field value and the prefix/suffix?
So that you can do things like "200€" or "$500". And if you need spaces like " minutes" you would add the space while filling the input field itself. What do you think?
Also, as mentioned in the other issue, is having the "Show suffix" and "Show prefix" yes/no toggles necessary? Wouldn't be simpler to just have two text fields that would display only if not empty?