Reform で作成されたフォーム オブジェクトがあり、モデルに含まれていないフォームからの 2 つの値を使用してプロパティを設定したいと考えています。
私のフォーム:
div.form-item.form-item--near
= f.input :employment_contract_type, collection: @presenter.employment_contract_codes_collection
= f.input :employment_contract_time, collection: ["Partial", "Complete"], as: :radio_buttons
私のフォームオブジェクト:
class FinancingRequestForm < Reform::Form
property :employment_contract_code
property :employment_contract_time, virtual: true
property :employment_contract_type, virtual: true
end
モデル:
# Table name: purchase_financing_customers
#
# id :integer not null, primary key
# employment_contract_code :string
module Purchase
class FinancingCustomer < ApplicationRecord
end
end
私はこのようなものが欲しいです:
class FinancingRequestForm < Reform::Form
ContractCodePopulator = lambda do |_|
time = employment_contract_type == "Complete" ? "C" : "P"
self.employment_contract_code = "#{send("employment_contract_type")}#{time}"
end
property :employment_contract_code, populator: ContractCodePopulator
property :employment_contract_time, virtual: true
property :employment_contract_type, virtual: true
end
しかし問題は、form.validate(request_params) を実行したときに de Populator がトリガーされないことです。
私は、employment_contract_code を他の 2 つの仮想値で構成したいだけです。
ありがとう!