Hotwire looks fantastic - having a bit of an issue with custom forms that it would be great to get some help on.
I’ve created a blank hotwire project, then a simple scaffold (monkey). The CRUD operations seems to work. Form data is sent as TURBO_STREAM and is handled by the scaffold controller and html.erb views.
<%= form_with(model: monkey) do |form| %>
… scaffold input …
<%= form.submit %>
<% end %>
When I try and create a very simple custom form for another model
<%= form_with(model: @customer, url: step2_path) do |f| %>
<%= f.submit “Next”, class: “btn btn-success” %>
<% end %>
The form is submitted as TURBO_STREAM and this error is shown in the browser console.
Form submission failed FormSubmission {state: 2, delegate: Navigator, formElement: form, formData: FormData, submitter: input.btn.btn-success, …} Error: Form responses must redirect to another location
at FormSubmission.requestSucceededWithResponse (turbo-aca352d862899e9670bf9741fcebf788fc606be14900e7dfd2569573c2e56213.js:433)
at FetchRequest.receive (turbo-aca352d862899e9670bf9741fcebf788fc606be14900e7dfd2569573c2e56213.js:297)
at FetchRequest.perform (turbo-aca352d862899e9670bf9741fcebf788fc606be14900e7dfd2569573c2e56213.js:278)
I can get a working app with this, but I loose all my controller variables
def create
redirect_to another_place_path, notice: ‘Customer was successfully created.’
end
I’ve read through a some of these posts, but can’t see a resolution.
Two questions…
-
Is there a way to turn off TURBO_STREAM for a form?
-
For backwards compatibility is there a way I can turn off all TURBO_STREAMing , then only enable this for the forms and links that I want?
Thanks for any help.