フォームを送信する前に、ユーザーが特定のフィールド、下の[支払い金額]フィールドに入力し、ステータス= "Closed"を選択したかどうかを判断して、保存する前に検証を実行したいと思います。彼が一方を他方なしで行う場合、フォームは保存されるべきではありません
ページを編集
<%= simple_form_for @invoice, :html => { :class => 'form-horizontal' } do |f| %>
<%= render "shared/error_messages", :target => @invoice %>
<%= f.association :customer, disabled: @invoice.persisted? %>
<%= f.input :due_date, as: :string, input_html: { class: "datepicker" }, disabled: @invoice.persisted? %>
<%= f.input :invoice_date, as: :string, input_html: { class: "datepicker" }, disabled: @invoice.persisted? %>
<%= f.input :payment_method, as: :select, :collection => [['Cash','Cash'],['Cheque','Cheque'],['In-House transfer','In-House transfer'],['Account Ledger','Account ledger']], :selected => ['Cash','Cash'] %>
<%= f.input :reference_no, :label => 'Payment Reference No', as: :string %>
<%= f.input :amount, as: :string %>
<%= f.input :payment_date, as: :string, input_html: {class: "datepicker"} %>
<%= f.input :status, as: :select, collection: Invoice::VALID_STATUS %>
Invoice.rbのVALID_STATUS=['ドラフト'、'オープン'、'クローズ'、'ボイド']
ユーザーがステータスをクローズに変更した場合、フォームに金額を入力する必要があります。ユーザーは、金額を入力せずにステータスをクローズに変更できないようにする必要があります