GithubHelp home page GithubHelp logo

cj / client_side_validations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davyjoneslocker/client_side_validations

1.0 2.0 0.0 619 KB

Rails 3 Client Side Validations

Home Page: http://bcardarella.com/post/4211204716/client-side-validations-3-0

client_side_validations's Introduction

ClientSideValidations

Build Status

Client Side Validations made easy for your Rails applications!

In addition to this README please checkout the wiki and ClientSideValidations GoogleGroup.

This repository is for Rails 3. For Rails 2 compatibility, try Rails 2 ClientSideValidations.

Project Goals

  1. Follow the best practices for client side validations developed by Luke Wroblewski
  2. Automatically extract and apply validation rules defined on the server to the client.
  3. In the cases where a server-side validation rule would not work on the client (i.e. conditional callbacks like :if, :unless) then do not attempt client side validations. Fall back to the server side validation.
  4. The client side validation error rendering should be indistinguishable from the server side validation error rendering.
  5. Wide browser compliancy. I've tested with IE8, seems to work OK.
  6. Work with any ActiveModel::Validations based model
  7. Validate nested fields
  8. Support custom validations
  9. Client side validation callbacks

Install

Include Client Side Validations in your Gemfile

gem 'client_side_validations'

Then run the install generator

rails g client_side_validations:install

This will install two files:

config/initializers/client_side_validations.rb
public/javascripts/rails.validations.js

Upgrading

Rails 3.1

Because the javascript file is now in the asset pipeline there is no need to rerun the generator after upgrading.

Rails 3.0

Always be sure to run

rails g client_side_validations:install

After upgrading Client Side Validations. There is a good chance that the rails.validations.js file has changed.

Usage

Rails 3.1

The javascript file is served up in the asset pipeline. Add the following to your app/assets/javascripts/application.js file.

//= require rails.validations

Rails 3.0

Client Side Validations requires jQuery version >= 1.6

Include the rails.validations.js file in your layout

<%= javascript_include_tag 'jquery', 'rails.validations'-%>

Turn on the validations for each form_for

<%= form_for @book, :validate => true do |book| -%>

Nested fields automatically inherit the :validate value. If you want to turn it off pass :validate => false to fields_for

<%= book.fields_for :pages, :validate => false do |page| -%>

Initializer

The initializer includes a commented out ActionView::Base.field_error_proc. Uncomment this to render your error messages inline with the input fields.

I recommend you not use a solution similar to error_messages_for. Client Side Validations is never going to support rendering these type of error messages. If you want to maintain consistency between the client side rendered validation error messages and the server side rendered validation error messages please use what is in config/initializers/client_side_validations.rb

Client Side Validation Callbacks

See the wiki

Known Issues

The major outstanding issue is with radio buttons. See the open ticket.

Legal

Brian Cardarella © 2011

@bcardarella

Licensed under the MIT license

client_side_validations's People

Contributors

amangale avatar bcardarella avatar burmajam avatar eostrom avatar gmile avatar godisemo avatar jcasimir avatar jonkessler avatar mat813 avatar mhenrixon avatar mvastola avatar pfeiffer avatar taavo avatar vhyza avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.