2

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>
  <div class="field">
    <%= f.label :middle_name, {:class => 'label'}%> 
    <%= f.text_field :middle_name,{:class => 'span3'}%>
  </div>
  <div class="actions" style="padding-left: 350px;">
    <%= f.submit "Save", :name => "save", :class => 'btn'%> 
    <%= f.submit "Submit", :name => "submit", :class => 'btn' %>
  </div>

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

Thanks.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Would you clarify what to you meant by: This is called before the form is submitted
Sure. Basically CSV will bind to the form.submit event and the code that you supply in the form.before callback will be run before the form is allowed to be submitted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.