? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
18 Mar 2019

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

avatar brianteeman brianteeman - open - 18 Mar 2019
avatar brianteeman brianteeman - change - 18 Mar 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Mar 2019
Category Administration com_fields Language & Strings Front End
avatar brianteeman brianteeman - change - 18 Mar 2019
Labels Added: ? ?
avatar AndySDH
AndySDH - comment - 18 Mar 2019

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?

avatar brianteeman
brianteeman - comment - 18 Mar 2019

Can you make it so that there are no spaces between the field value and the prefix/suffix?

There aren't any

avatar AndySDH
AndySDH - comment - 19 Mar 2019

There are for me:

image

avatar Bakual
Bakual - comment - 19 Mar 2019

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?

avatar franz-wohlkoenig franz-wohlkoenig - change - 11 Apr 2019
Category Administration com_fields Language & Strings Front End Administration com_fields Front End
avatar brianteeman brianteeman - change - 19 Apr 2019
Labels Removed: J4 Issue
avatar joomla-cms-bot joomla-cms-bot - change - 19 Apr 2019
Category Administration com_fields Front End Administration com_fields Language & Strings Front End
avatar brianteeman
brianteeman - comment - 19 Apr 2019

Updated to remove conflicts and simplify as per @Bakual suggestion

avatar HLeithner
HLeithner - comment - 23 Apr 2019

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.

avatar brianteeman
brianteeman - comment - 23 Apr 2019

Sorry I dont understand your plural comment

avatar HLeithner
HLeithner - comment - 23 Apr 2019

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

avatar wilsonge
wilsonge - comment - 23 Apr 2019

How is that not covered by passing this through the Text::Plural already?

avatar Bakual
Bakual - comment - 23 Apr 2019

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".

avatar HLeithner
HLeithner - comment - 23 Apr 2019

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...

avatar wilsonge wilsonge - change - 23 Apr 2019
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-04-23 10:36:53
Closed_By wilsonge
avatar wilsonge wilsonge - close - 23 Apr 2019
avatar wilsonge wilsonge - merge - 23 Apr 2019
avatar brianteeman
brianteeman - comment - 23 Apr 2019

Thanks

avatar wilsonge
wilsonge - comment - 23 Apr 2019

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!

Add a Comment

Login with GitHub to post a comment