Custom Turbo Stream action: reset a form after success

2991
0

After a successful inline create, I usually want to clear the form. You can replace the whole form partial, but sometimes you want to preserve other state (like which field was focused) and simply reset values. A clean Hotwire approach is a custom Turbo Stream action reset_form that calls form.reset() on the target. The server emits a <turbo-stream action='reset_form' target='new_item_form'>, and the client registers Turbo.StreamActions.reset_form. This keeps the UI intent server-driven (“reset it”) without re-rendering markup. I still pair it with a normal prepend to add the new item. If validation fails, the server replaces the form with errors (422) as usual.