Client side validation is not working while applying conditional validation in rails 4

前端 未结 1 1716
死守一世寂寞
死守一世寂寞 2021-01-27 01:59

I am using client side validation gem. Client side validation is not working while applying conditions. Here is my Model Class.

validates_uniqueness_of :project_         


        
相关标签:
1条回答
  • 2021-01-27 02:41

    Client_side_validations does not validate conditionals out-of-the-box. What you are observing is the intended behavior.

    In order to validate conditionals, you need to force them in your form:

    f.number_field :price, :validate => { :numericality => true}
    

    In addition, according to the documentation, the value needs to evaluate to true at the time the form is being generated. However, there is a hack for this: The method that determines whether the condition evaluates to true is called run_conditional (source), so you can override that method in your model:

    def run_conditional(method_name_value_or_proc)
      (:project_type_fixed? == method_name_value_or_proc) || super
    end
    
    0 讨论(0)
提交回复
热议问题