【问题标题】:Reform - Access parent form params inside of nested form scope改革 - 访问嵌套表单范围内的父表单参数
【发布时间】:2017-09-12 20:59:13
【问题描述】:

我正在使用Reform 1.2.6 并且有一个带有验证的嵌套表单

简化:

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

参数正确嵌套,我只需要一种从嵌套表单访问父表单输入的方法。问题是嵌套表单似乎只能访问其参数集,而不是整个参数。

【问题讨论】:

    标签: ruby-on-rails ruby forms parameters reform


    【解决方案1】:

    所以,基本上你真正需要的是使用 Disposable::Twin::Parent 功能。

    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
    

    另外,你可以阅读这个主题:https://github.com/apotonick/disposable/issues/61

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      相关资源
      最近更新 更多