No Code Attached Yet bug
avatar lushdomain
lushdomain
24 Dec 2023

Steps to reproduce the issue

None, it just happens

Expected result

See Below

Actual result

See Below

System information (as much as possible)

J5.0.1
Chrome Browser

Additional comments

When I add a text type custom field in an article an extra space is added directly after the content of the field. I've double checked my entries for additional spaces, there are none.

Article text in editor
operates in {field 6}, {field 7}. We cover........

Rendered article text in browser
operates in Basingstoke , Hampshire . We cover.....

You can see the extra space being rendered before the , and the .

Code from Console

<p>operates in <span class="field-value ">Basingstoke</span>
, <span class="field-value ">Hampshire</span>
. We cover......</p>

This is exactly how the code is produced in the page, a bit "janky" I'd say, but may have no bearing on the issue.

This issue only seems to happen if the field is immediately followed by punctuation, if it's followed by another word there's no extra space. Although in other places in the article the field is followed by a dash ( - ) with no extra space. But, if followed by a ( ? ) then an extra space is inserted between the field and the ( ? )

Merry Christmas everyone.

avatar lushdomain lushdomain - open - 24 Dec 2023
avatar joomla-cms-bot joomla-cms-bot - change - 24 Dec 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Dec 2023
avatar lushdomain
lushdomain - comment - 6 Jan 2024

Just wondering if anyone on the team has seen this yet?

avatar brianteeman
brianteeman - comment - 6 Jan 2024

confirmed

avatar Quy Quy - change - 6 Jan 2024
Labels Added: bug
avatar Quy Quy - labeled - 6 Jan 2024
avatar Saswatsusmoy
Saswatsusmoy - comment - 28 Jan 2024

Here's a potential solution using the FieldsHelper::render() function that might help resolve this problem:

  1. Override the Render Method: You can override the FieldsHelper::render() method in your template or plugin to control how the fields are outputted.

    // Load the FieldsHelper
    JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
    
    // Get the custom fields for a specific item
    $jcFields = FieldsHelper::getFields('com_content.article', $item, true);
    
    // Loop through the fields and render them without extra spaces
    foreach($jcFields as $field) {
        // Render the field and trim any whitespace
        $fieldOutput = trim(FieldsHelper::render($field->context, 'field.render', array('field' => $field)));
        echo $fieldOutput;
    }

    In this snippet, trim() is used to remove any leading or trailing whitespace from the rendered field output.

Hope this helps!

avatar brianteeman
brianteeman - comment - 28 Jan 2024

chatGPT is not a solution

avatar Saswatsusmoy
Saswatsusmoy - comment - 28 Jan 2024

chatGPT is not a solution

Actually I tried solving using the same logic and code only, but for explanation I used ChatGPT

avatar brianteeman
brianteeman - comment - 28 Jan 2024

... and did you actually try the code? Did it really solve the reported problem?

avatar Saswatsusmoy
Saswatsusmoy - comment - 29 Jan 2024

... and did you actually try the code? Did it really solve the reported problem?

Yeah, the code mentioned above isn't the actual code, there's a different code but for like validation if my approach is correct I provided the sample code. I will be raising a PR with the actual code which is solving this problem

Add a Comment

Login with GitHub to post a comment