mercredi 28 juin 2017

Check validation if radio option selected Rails 4

I have two fields that appear when a certain radio box is selected. The value of that radio box is 4. I need the validation to check for presence: true when that specific box is clicked and the form is submitted with empty fields and cannot seem to get that to work.

check_request.rb:

validates :commission_collected, presence: true, if: :commission_invoice?
validates :commission_percentage, presence: true, if: :commission_invoice?

def commission_invoice?
  check_request_type == 4
end

Aucun commentaire:

Enregistrer un commentaire