-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested form, two levels deep #454
Comments
Keep in mind that populators are only called when the incoming document contains a corresponding fragment. "Not working" - what is "not working"? 😂 Does your computer start up? Have you plugged in the power cable? Does the form validate? What's missing? What's your input hash? What's the resulting form? |
@domi91c did you solve this problem? |
@apotonick the problem is that I can't use collection in collection on form. For example I have such code in Reform::Form: collection :contacts, populate_if_empty: Contact do
properties :first_name, :last_name, :agency_id, :nickname,
:middle_name, :suffix, :prefix, :title
collection :phones, populate_if_empty: ContactPhone, populator: ->(fragment:, **) {
return skip! if fragment['delete'] == 'true' && !fragment['id']
if fragment['id']
item = phones.find_by(id: fragment['id'])
phones.delete(item) if fragment['delete'] == 'true' && !item.primary
item ? item : phones.append(model.phones.build)
else
phones.append(model.phones.build)
end
} do
properties :number, :type, :primary
validates :number, presence: true
end
end and on view I have (just for tests):
but rails throws error:
When I write accept_nested_attributes :phones in Contact model it works (ContactPhone belongs_to Contact). |
Hi @unrooty, please try this |
@apotonick when I wrote p form.contacts[0].phones, I got
But when I tried to pass it to ff.fields_for, I've got error:
Another thing that I want to say is that after |
The behavior of Reform is correct, it returns an "enumeratable" object for |
The most strange thing for me that I use two same objects in fields_for, but on top level it work and in nested fields_for it stops working. I start to hate Rails... |
Well, we wrote the Formular gem to avoid Rails form helpers, but it's still lacking docs. |
@apotonick thanks for answers :) |
Please let me know what is the problem! |
@apotonick I didn't find solution and desided to use |
I had my Reform form working with one nested model, but I need that model to contain another nested model. A tutorial has_many steps, a step has_many images. Here's my attempt:
Is this totally wrong? It's not working at the moment.
The text was updated successfully, but these errors were encountered: