Precognition doesn't work when combinated with conditional fields helper · Issue #11833 · statamic/cms · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This way I don't have to add x-ref and novalidate manually to every form and I don't have to override the vendor input renderers. It works as expected.
I created a form blueprint with a select and one textarea, selecting option 2 should show the textarea but it does not. When I remove the 'form.' prefix in my addToRenderableFieldAttributes function the conditional rendering works as expected, but precognition doesn't work anymore. The form prefix is necessary as documented here: https://statamic.dev/forms#precognition
So I sort of hit a wall, since I feel like there should be an intended way both techniques can work nicely together but I can't find to figure it out. I also followed the docs so I decided to do a bug request.
Thanks in advance.
Jeroen Balk
How to reproduce
Create a form with conditional logic
Implement Precognition in the form (publish the field renderers or extend the js driver, doesn't really matter)
Check if x-model has 'form.' prefix
Try conditional logic.
Logs
Environment
EnvironmentApplication Name: Buurtvereniging EibergsewegLaravel Version: 12.16.0PHP Version: 8.4.7Composer Version: 2.8.9Environment: localDebug Mode: ENABLEDURL: buurtverenigingeibergseweg.nl.ddev.siteMaintenance Mode: OFFTimezone: UTCLocale: enCacheConfig: NOT CACHEDEvents: NOT CACHEDRoutes: NOT CACHEDViews: CACHEDDriversBroadcasting: logCache: fileDatabase: mariadbLogs: stack / singleMail: smtpQueue: syncSession: fileStoragepublic/storage: NOT LINKEDStatamicAddons: 0Sites: 1Stache Watcher: Enabled (auto)Static Caching: DisabledVersion: 5.56.0 Solo
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
The text was updated successfully, but these errors were encountered:
I get the idea of changing the scope, but it seems that it doesn't work. That results in the following error:
What I also tried:
NOT prefixing x-model with 'form.' in addToRenderableFieldAttributes
NOT prefixing show_field scope in addToRenderableFieldData with 'form.'
and passing js="precognition:form" (passing scope) to the jsDriver.
This renders $data.form in the conditions and prefixed the form handles with form. No errors, but precognition is broken and conditional showing of fields also doesn't work.
Uh oh!
There was an error while loading. Please reload this page.
Bug description
Hello,
To get precognition to work I did extend the alpine driver like this:
This way I don't have to add x-ref and novalidate manually to every form and I don't have to override the vendor input renderers. It works as expected.
Then I wanted to add conditional showing of fields to the form, so I included the helper in the as documented here: https://statamic.dev/tags/form-create#including-the-scripts
After that I added the x-if around the field+label inside the {{fields}} loop. The file looks like this:
I created a form blueprint with a select and one textarea, selecting option 2 should show the textarea but it does not. When I remove the 'form.' prefix in my addToRenderableFieldAttributes function the conditional rendering works as expected, but precognition doesn't work anymore. The form prefix is necessary as documented here: https://statamic.dev/forms#precognition
So I sort of hit a wall, since I feel like there should be an intended way both techniques can work nicely together but I can't find to figure it out. I also followed the docs so I decided to do a bug request.
Thanks in advance.
Jeroen Balk
How to reproduce
Logs
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
The text was updated successfully, but these errors were encountered: