Dawid
Dawid

Reputation: 654

Disable simple_fields_for that are persisted?

Hi I'm learing to use accepts_nested_attributes and I have a simple_fields_for in my simple_form and everything works great and I can add object with nested_attributes. But now I would like to disable already persisted fields if user wants to add another one. It looks like:

 = f.simple_fields_for :annexes do |an|
   = an.input :number, label: "Numer", required: false

I would like to disable every object, that is already persisted. I tried to add some if statement, but the 'an' is SimpleForm::FormBuilder object, not Annex as I expected. How can I achieve this?

Upvotes: 0

Views: 383

Answers (1)

Dawid
Dawid

Reputation: 654

I got it. I found that we can get object by calling object inside simple_fields_for block. Now I can check:

  = f.simple_fields_for :annexes do |an|
    - if an.object.persisted?
      ...disabled fields...
    - else
      ... normal fields...

Upvotes: 1

Related Questions