Reform - Access parent form params inside of nested form scope

746 views Asked by At

I'm using Reform 1.2.6 and have a nested form with validation

Simplified:

class UserForm < Reform::Form
  property :date_of_birth

  property health_profile do
    property :diagnosed_with_condition_at

    validate :diagnosed_date

    def diagnosed_date
      # need to get access to date_of_birth here
      # validate that diagnosed_with_condition_at is after date of birth
    end
  end
end

Params come in properly nested, I just need a way to get access to parent form inputs from the nested form. The problem is that nested form seems to only have access to its set of params, and not the whole params.

1

There are 1 answers

0
Timofey Lavnik On

So, basically what you really need here is to use Disposable::Twin::Parent feature.

require 'disposable/twin/parent'

class UserForm < Reform::Form

  feature Disposable::Twin::Parent

  property :date_of_birth

  property health_profile do
    property :diagnosed_with_condition_at

    validate :diagnosed_date

    def diagnosed_date
      self.parent.date_of_birth
    end
  end
end

Also, you can read this topic: https://github.com/apotonick/disposable/issues/61