Closed shifuma closed 1 year ago
I‘d start by setting the value of slideout
in the x-data
definition to true
when there are errors and seeing how that goes.
Thanks for the reply. I tried this:
{% if address is defined and address.hasErrors() %}
{% do craft.app.session.setError('Error.') %}
<script>
htmx.trigger('#notification', 'refresh');
document.addEventListener('alpine:init', () => {
Alpine.data('slideout', () => ({
slideout: true,
}))
})
</script>
{% endif %}
But unfortunately no luck; it still closes the slideout. I note that you also say not to use Alpine.data
here: https://putyourlightson.com/plugins/sprig#alpine-js
I'm really poor with JS so appreciate if you can help. Otherwise I'll try over on the Alpine discord. Thanks!
I actually meant inlining the condition as follows.
x-data="{ slideout: {{ address is defined and address.hasErrors() ? 'true' : 'false' }} }"
Ah that did it! I'd actually tried it before, but I must have still had s-replace="#address-fields"
on the form inside the slideout.
Thanks Ben!
Great!
I'm building an address management system for Commerce and would like it to work similarly to how it does in the control panel, meaning Slideouts.
I've got adding, editing and deleting addresses working well but adding server-side validation complicates things. Basically, the slideout is closed when the form is submitted, meaning the errors don't show.
If I add
s-replace="#address-fields"
to<form id="address-form">
the slideout stays open and the validation errors show. However, the slideout stays open after a successful submission and the notification doesn't show until the page is refreshed.I would like to combine these two scenarios. I thought adding
{% do sprig.retarget('#manage-addresses') %}
to{% if success ... %}
would do it, but that has some strange effect. I've played around with a few other options like this, but not found a solution yet. My code is below and I know it's a lot, but I'd appreciate any pointers!