Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Fix JavaScript error caused by using "switcher" layout for radio buttons in subforms #43804

Merged
merged 8 commits into from
Aug 10, 2024
Merged

[5.1] Fix JavaScript error caused by using "switcher" layout for radio buttons in subforms #43804

merged 8 commits into from
Aug 10, 2024

Conversation

mattelkins-bluefrontier
Copy link
Contributor

@mattelkins-bluefrontier mattelkins-bluefrontier commented Jul 18, 2024

Pull Request for Issue #43800.

Summary of Changes

Updated subform JavaScript behaviours to look for .switcher when .radio is not found.

Testing Instructions

  1. Add the following subform to a form:
<field
    name="switcher_test_subform"
    type="subform"
    label="Switcher Test"
    multiple="true"
    layout="joomla.form.field.subform.repeatable">
    <form>
        <fieldset>
            <field
                name="switcher_test"
                type="radio"
                label="Switcher Test"
                layout="joomla.form.field.radio.switcher"
                default="0"
                >
                <option value="0">JNO</option>
                <option value="1">JYES</option>
            </field>
        </fieldset>
    </form>
</field>
  1. Access the form and click + to add a subform item.

Actual result BEFORE applying this Pull Request

A subform item is created and added to the subform, but the following JavaScript error occurs, which interferes with any other JavaScript attempting to run.

TypeError: Cannot read properties of null (reading 'nodeName')
    at joomla-field-subform.js?25ff4b:305:31
    at Array.forEach (<anonymous>)
    at JoomlaFieldSubform.fixUniqueAttributes (joomla-field-subform.js?25ff4b:263:14)
    at JoomlaFieldSubform.addRow (joomla-field-subform.js?25ff4b:195:10)
    at JoomlaFieldSubform.<anonymous> (joomla-field-subform.js?25ff4b:95:16)

(Error trace taken with debug mode enabled.)

Expected result AFTER applying this Pull Request

A subform item is created and added to the subform without any JavaScript errors occurring.

Link to documentations

No documentation changes for docs.joomla.org needed.
No documentation changes for manual.joomla.org needed.

@Fedik
Copy link
Member

Fedik commented Jul 18, 2024

There need to fix JS.
Adding this class can break some styling for templates that have some css for .radio

@joomla-cms-bot joomla-cms-bot added the NPM Resource Changed This Pull Request can't be tested by Patchtester label Jul 18, 2024
@mattelkins-bluefrontier
Copy link
Contributor Author

Many thanks for your feedback, @Fedik. Updated.

@Fedik
Copy link
Member

Fedik commented Jul 18, 2024

Thanks, yes that will work.
However I think it still not very reliable solution, when markup/class will changes at some point.
What we need: is to pick closest fieldset, that direct parent of the radio/checkbox inputs (fieldset>input or fieldset>div>input), but ignore any other parent fieldsets.

hmhm, I will look later, in detail.

@Fedik
Copy link
Member

Fedik commented Jul 18, 2024

I have tested this item ✅ successfully on c2802cf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43804.

@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on c2802cf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43804.

@Quy
Copy link
Contributor

Quy commented Jul 21, 2024

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43804.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 21, 2024
@LadySolveig LadySolveig added this to the Joomla! 5.1.3 milestone Jul 26, 2024
@bembelimen bembelimen merged commit e4a7198 into joomla:5.1-dev Aug 10, 2024
0 of 2 checks passed
@bembelimen
Copy link
Contributor

Thx

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Aug 10, 2024
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 11, 2024
@mattelkins-bluefrontier mattelkins-bluefrontier deleted the subform-radio-switcher-js-fix branch August 14, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug NPM Resource Changed This Pull Request can't be tested by Patchtester
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[5.1.2] Using radio buttons with the "switcher" layout produces a JavaScript error in subforms
7 participants