Precognition doesn't work when combinated with conditional fields helper #11885
Replies: 3 comments
-
I think you need to override addToRenderableFieldData():
|
Beta Was this translation helpful? Give feedback.
-
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:
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. |
Beta Was this translation helpful? Give feedback.
-
Passing the scope will mean it's applied all the time, which isnt what you want. What about (this will use 'form' when no other scope is applied). public function addToRenderableFieldData($field, $data)
{
return [
'show_field' => $this->renderAlpineShowFieldJs($field->conditions(), $this->scope ?? 'form'),
];
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
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
Beta Was this translation helpful? Give feedback.
All reactions