verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 68 forks source link

JavaScript Errors with Conditions on Fields within Repeater Field in Formie 3.0.0-beta.14 #1915

Open mauricepattyn opened 2 weeks ago

mauricepattyn commented 2 weeks ago

Describe the bug

I'm using Craft CMS 5 with Formie 3.0.0-beta.14, and I encounter the following JavaScript errors when using conditions on fields within a repeater field. Note that these errors are from compiled JavaScript files.

Errors:

TypeError: t.querySelectorAll is not a function or its return value is not iterable
    at window.FormieConditions.querySelectorAllRegex (conditions.js?v=1717155018:1:4372)
    at conditions.js?v=1717155018:1:1497
    at Array.forEach (<anonymous>)
    at window.FormieConditions.getFieldConditions (conditions.js?v=1717155018:1:1235)
    at conditions.js?v=1717155018:1:649
    at NodeList.forEach (<anonymous>)
    at window.FormieConditions.initFieldConditions (conditions.js?v=1717155018:1:623)
    at HTMLDivElement.<anonymous> (conditions.js?v=1717155018:1:513)
    at window.FormieRepeater.initRow (repeater.js?v=1717155018:1:1327)
    at repeater.js?v=1717155018:1:1989

TypeError: t.classList.remove is not a function
    at formie.js?v=1717155018:1:9765
    at Array.forEach (<anonymous>)
    at i (formie.js?v=1717155018:1:9740)
    at c.removeError (formie.js?v=1717155018:1:15281)
    at formie.js?v=1717155018:1:14653
    at Array.forEach (<anonymous>)
    at c.validate (formie.js?v=1717155018:1:14606)
    at c.blurHandler (formie.js?v=1717155018:1:17380)

Additional Information: Craft CMS version: 5.1.9 Formie version: 3.0.0-beta.14 Browser: Chrome

Please let me know if any additional information is needed.

Thank you for your attention to this matter!

Steps to reproduce

  1. Create a form using Formie 3.0.0-beta.14 in Craft CMS 5.
  2. Add a repeater field with conditions.
  3. Trigger the conditions within the repeater field.

Form settings

Craft CMS version

5.1.9

Plugin version

3.0.0-beta.14

Multi-site?

No

Additional context

No response

engram-design commented 2 weeks ago

Just to clarify, are the conditions on fields within the Repeater, or outside? Just want to ensure that I replicate your setup.

mauricepattyn commented 2 weeks ago

Hi @engram-design

Thanks for the fast response. Just to clarify, the conditions are on fields within the Repeater field, not outside.

Thank you!

engram-design commented 2 weeks ago

Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-5 as 3.0.0-beta.14".

mauricepattyn commented 4 days ago

Hi @engram-design

This issue was partially resolved, but the fix only works for repeater fields that do not have a minimum instance set. In my form, there is a minimum instance of 1, and the problem persists. Could you please look into this? I am now using version 3.0.0-beta.15.

engram-design commented 4 days ago

I can't seem to reproduce that I'm afraid, conditions for fields are being applied correctly when the default Repeater row is created on page load (with the minimum instance of 1). It's the exact same error though?

mauricepattyn commented 2 days ago

Hi @engram-design

Thank you for the quick response. I'd like to clarify the issue I'm experiencing.

When I create a repeater field and set the minimum instance to 1 (leaving the maximum empty), I add radio buttons with two options, where option 1 is selected by default. Then, I add a text field with the condition that it should only be displayed when option 1 is selected. In this setup, the text field should be visible immediately because the instance is set to 1 and option 1 is selected by default.

However, this does not work for me. The conditions only seem to work when I add a new row to the repeater. This issue occurs with all conditions in repeater fields that should be displayed by default. It appears that the JavaScript only triggers when a new row is added.

To ensure this wasn't an isolated case, I set up a new project and installed the plugin on a clean project, but I still experience the same issue.

I am currently using version 3.0.0-beta.15.

Thank you for your help!

engram-design commented 1 day ago

Thanks for the clarification, I've managed to get to the bottom of this one, there were a few moving parts to this.

Should be fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-5 as 3.0.0-beta.15".