Rails 4 Client Side Validation

The rails way of doing client side validation (Rails 4 with simple_form)

There is client_side_validations, but is not longer maintained. Probably the best way is using some jQuery plugin like jquery-validation.

Rails 4 client side validation

From the Google.

http://rubygems.org/gems/rails4_client_side_validations

https://github.com/amatsuda/html5_validators

Also this guy seemed to have gotten the same gem you are using to work by using the 4-0-beta branch.

Client Side Validations and Rails4

If the 4-0-beta branch works for you, consider helping to maintain the gem to keep it alive.

To use a certain git repo version in your Gemfile:

gem 'client-side-validations', :git => 'https://github.com/bcardarella/client_side_validations/tree/4-0-beta'

Client side form validation rails

Using a singly quotation instead of the double seems to do the trick.

<%= form.text_field :twitter_link, 
class: "form-control",
required: true,
pattern: '^(?:https?:\/\/)?(?:(?:www|m)\.)?twitter\.com\/\w+\/status\/\d+(?:\/\/?)?$',
title: "Twitter Comment URL" %>

Not sure why i didn't try this before because i have ran into similar issues in the past with double vs single

custom validation with client side validation

I hope I understand your questions.

  1. You want to know how to get a validation that using a nested resource

  2. You want to know how to make that validation pass through to client side validation

For validations: add the reference to the associated model

def invoice_date_lesser
if invoive_date < quote.quote_date
errors.add(:invoice_date, 'invoice date invalid')
end

end

For client side validations: add validate => true in your form_for

form_for @model, :validate => true do |f|

Adding client side validations to modal using 'bootstrap_form' gem

For client side validations you will need Javascript. Client side validation entails that a validation occurs BEFORE it hits the server, the validations you have setup are Rails validations and those occur AFTER the form has been submitted. If you want to validate a form before it is submitted I recommend a Jquery plugin such as http://jqueryvalidation.org/ . Adding Jquery validation to your project will allow you to check your forms before they are submiited to the server.



Related Topics



Leave a reply



Submit