js-test is still included even when disabled
What happened?
The form on this page does not have js-test enabled, nor is it enabled globally in the settings: hxxps://dragonflyshipping.ca/en/return-pickup-form/
Errors and Stack Trace (if available)
Since the markup is not in the form, we get
js-test.js?v=1727877762:3 Uncaught TypeError: Cannot set properties of null (setting 'value')
at HTMLDocument.jsTest (js-test.js?v=1727877762:3:67)
at e._dispatchEvent (freeform.js?v=1726849393:2:233203)
at e.<anonymous> (freeform.js?v=1726849393:2:234236)
at freeform.js?v=1726849393:2:221431
at Object.next (freeform.js?v=1726849393:2:221536)
at freeform.js?v=1726849393:2:220450
at new Promise (<anonymous>)
at zt (freeform.js?v=1726849393:2:220195)
at freeform.js?v=1726849393:2:234106
How can we reproduce this?
- Update from freeform 4 to 5 (?)
- Enabled both GTM and Honeypot, disabled js-test
- We add assets manually: the js-test file is still included.
Freeform Edition
Pro
Freeform Version
5.6.2
Craft Version
4.12.4.1
When did this issue start?
After upgrading from older Freeform version
Previous Freeform Version
from latest 4.x, updated last week
Sorry for the trouble @nitriques,
You mention you add assets manually. What does your template code look like for adding these? 🙂
We've recently made some improvements with this, so I wonder if that's the issue: https://docs.solspace.com/craft/freeform/v5/developer/js-plugin#loading-freeform-js-manually
Ideally, you might be using something like this now:
{{ freeform.loadScripts([
"freeform",
"recaptcha.v3",
"stripe"
]) }}
Hey @kjmartens
Yes it does:
{{ freeform.loadScripts([
"freeform",
"freeform.js-test",
"recaptcha.v2-checkbox",
]) }}
The js-test is enabled, so we need included include it, but it is disabled for at the form level (or globally via the settings in the cms).
Is there a way to prevent that 'auto-inclusion' ?
The other option you have is to only load scripts that are specific to what the form has enabled:
{{ freeform.loadFreeformPlugin() }}
{{ freeform.loadFormSpecificScripts(form) }}
In the meantime, I will see if there's a way to prevent the JS Test script from erroring if a form has it disabled while loadScripts() calls it. 🙂