Handle form errors with a stimulus class

We need to keep the focus in place when submitting the form. We are using a data-turbo-permanent for that. We were rendering the error form with a turbo stream. The problem was that turbo streams ignore permanent elements as per this https://github.com/hotwired/turbo/pull/688, so the system wasn't updating the input field as expected.

Handling this as the stimulus level will also help with managing additional error states (such as the one we need for confirmations).
This commit is contained in:
Jorge Manrubia
2025-05-07 08:46:47 +02:00
parent 6cb1762588
commit 55ea460d3e
5 changed files with 24 additions and 11 deletions
@@ -19,10 +19,6 @@ export default class extends Controller {
event.target.select()
}
reset(event) {
this.element.reset()
}
showPicker(event) {
if ("showPicker" in HTMLInputElement.prototype) {
event.target.showPicker()