Turbo adding a new fields_for in the form

Gustavo Pares Gustavo Pares posted on 2023-04-26 12:58:19 UTC

Currently I have this

```
= turbo_frame_tag "xxx" do
  = f.fields_for :documents, @onboarding.documents.build do |task|
    = render 'shared/document_upload', form: task
```

update.turbo_stream.haml
```
= turbo_stream.update "xxx" do
  = render 'shared/document_upload', form: task



How can I pass the fields for form object to the update.turbo_stream,   or how can I build a new fields_for on the update?

Person who answers correctly will get $50 through paypal!!

Im stumped!

David Kimura PRO said over 1 year ago :
I might be misunderstanding the issue, but would turbo & turbo frame tags be the best solution here? When you have a form object and you're submitting the form, I don't think that the Rails controller can respond with a new form for the task like you're doing in the update. (at least not with how you have it setup like that).

Are you trying to do something like nested forms? Once the user uploads a document, you want it to add a new field where they can select an additional document? If this is the case, it may be better to use a Stimulus controller. This episode may help. https://www.driftingruby.com/episodes/nested-forms-from-scratch-with-stimulusjs

Login to Comment
Back to forums