Client_Side_Validation gem in Rails

user1069624 Source

I'm using the client_side_validation gem in my multi-model form. It's working fine, but I have one issue. The form has a save button, which should enable the user to save the form for later. When this button is clicked, nothing happens, I stay in the same page. I know I have validation messages, but the user should be able to complete them later.

How can I have a form button that works normally (calls the required action) while having client side validation.

Thank you.

This is my form if it will help..

<%= form_for @applicant, :validate => true do |f| %>
  <div class="field">
    <%= f.label :first_name, {:class => 'label'}%> 
    <%= f.text_field :first_name ,{:class => 'span3'}%>  
  <div class="field">
    <%= f.label :middle_name, {:class => 'label'}%> 
    <%= f.text_field :middle_name,{:class => 'span3'}%>
  <div class="actions" style="padding-left: 350px;">
    <%= f.submit "Save", :name => "save", :class => 'btn'%> 
    <%= f.submit "Submit", :name => "submit", :class => 'btn' %>

So I would like to go to the create action when I click the save button, even if I have validation errors..




answered 7 years ago Carlos Ramirez III #1

Until the release of client_side_validations 4.0, I don't think there is a straight-forward way to do this. See this discussion on Github.

For the time being, I have usually worked around this problem by using the CSV callbacks, specifically clientSideValidations.callbacks.form.before(form, eventData). This is called before the form is submitted and if you disable or remove any of the inputs which require validation, you should be able to submit the form without issue.

This is a less than ideal solution, and it will be much nicer once we can toggle validation on the form level using client_side_validations 4.0.

comments powered by Disqus