No Code Attached Yet bug
avatar Scrabble96
Scrabble96
31 Oct 2023

Steps to reproduce the issue

In J4 I have a newsflash module which displays a single article consisting of content from custom fields and uses a Newsflash_item override for display. The override has a div with the text 'Next Concert' used as the first text for the article displayed and just before the concert title. However, if there is a value in field #5 - e.g. "Sold Out" - then that would be shown instead of the 'Next Concert' but not if it's empty. The php is like this [extract]:

<div class="home-news-row article">
    <div class="home-concert-title">
        <div class="concert-message"><?php echo $item->jcfields[5]->value; ?></div><div class="our-next-concert">OUR NEXT CONCERT: </div><div class="concert-title d-md-inline-block"><h2><a href="<?php echo $item->link; ?>" title="read more about this concert"><?php echo $item->title; ?></a></h2></div>
    </div>
 </div>

and the CSS like this:

.home-news-row .concert-message:empty ~ .our-next-concert {
  background-color: var(--theme-contrast);
  color: var(--theme-dark);
  margin: 0 16px 8px 0;
  padding: 0.5rem 1rem 0.5rem;
  font-size: 1.75rem;
  font-weight: bold;
}
.home-news-row .concert-message:not(:empty) ~ .our-next-concert {
  display: none;
}
.home-news-row .concert-message,
.home-news-row .our-next-concert {
  display: inline-block;
}
.home-news-row .concert-message:empty {
  display: none;
}

Expected result

In Joomla 4.4.0 it renders correctly:

j4-empty-div

Actual result

j5-empty-div

Where you can see that not only is 'Our Next Concert' not displaying, but for some reason there is space and a new line added into the 'concert message' div. Coincidentally - or not - when I viewed the page source and copied and pasted the line into Word, I counted the number of spaces added to the html as being exactly the same number as the characters in "echo $item->jcfields[5]->value;" i.e. 31.

System information (as much as possible)

Linux server
10.6.15-MariaDB-cll-lve-log
PHP 8.1.24

Additional comments

avatar Scrabble96 Scrabble96 - open - 31 Oct 2023
avatar joomla-cms-bot joomla-cms-bot - change - 31 Oct 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 31 Oct 2023
avatar brianteeman
brianteeman - comment - 31 Oct 2023

Just wrap the concert message div with a php check to see if there is a value

avatar HLeithner
HLeithner - comment - 1 Nov 2023

Hmm that's strange, what have we changed in custom fields? this shouldn't happen of course and as workaround you can use <?php echo trim($item->jcfields[5]->value); ?>

What is the field type?

avatar Scrabble96
Scrabble96 - comment - 1 Nov 2023

Just wrap the concert message div with a php check to see if there is a value

Sorry, but I don't know what you mean. However, I have checked the database and there is no value for field nbr 5 for that article

avatar Scrabble96
Scrabble96 - comment - 1 Nov 2023

Just wrap the concert message div with a php check to see if there is a value

Sorry, but I don't know what you mean. However, I have checked the database and there is no value for field nbr 5 for that article

That works! Thank you. It is a standard text field.

I did create an override for layouts > com_fields > field and fields to compare both render.php files with J4 and could see no difference.

avatar drmenzelit
drmenzelit - comment - 2 Nov 2023

I can confirm the issue: in 4.4 the value of an empty text custom field is really empty, in 5.0 the value is not empty. A workaround is to use rawvalue instead
<?php echo $item->jcfields[5]->rawvalue; ?>

But I don't know (yet) which change in 5.0 is responsible for this effect.

avatar Quy Quy - change - 2 Nov 2023
Labels Added: bug
avatar Quy Quy - labeled - 2 Nov 2023
avatar drmenzelit
drmenzelit - comment - 2 Nov 2023

Here is a screenshot of the var_dump from two articles in Joomla 5.0, the first one has the value "Sold out" entered in the test field, the second one has no value (no entry for this field in the database neither)
grafik

Similar var_dump in Joomla 4.4 (first article with empty field, value and rawvalue are empty. Second article with text in field, value and rawvalue have different length)
grafik

avatar lushdomain
lushdomain - comment - 2 Nov 2023

I can confirm I have just encountered the same issue adding a custom text field to an article override in J5. Adding the "trim" command as mentioned above solved the issue. I double checked I had not inadvertently added a space, which I had not.

avatar angieradtke
angieradtke - comment - 3 Nov 2023

Same issue here;
In my case, this causes my xampp to crash locally. I have some fields.... -)
trimming the output helps, but the cause is probably located in administrator/components/com_fields/src/Helper/FieldsHelper.php
Maybe in Line: 229 , but i'm not sure

				if (\is_array($value)) {
					$value = implode(' ', $value);
				}
avatar Fedik Fedik - close - 4 Nov 2023
avatar Fedik
Fedik - comment - 4 Nov 2023

Please test #42285

avatar Fedik Fedik - change - 4 Nov 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-11-04 09:41:48
Closed_By Fedik

Add a Comment

Login with GitHub to post a comment