Giter Site home page Giter Site logo

formtastic_validation's Introduction

formtastic_validation

Introduction

Formtastic validation adds client side validation to your forms. Visit the demo app and its repo to see it in action.

Features

  • works with existing formtastic code. no need to modify anything
  • javascript lib agnostic.
  • no AJAX that pounds your servers. its completely client side javascript
  • unobtrusive and very light weight

Dependencies

Installation

  $ gem install formtastic_validation

Remember to add the gem into your bundler Gemfile

Then run the generators to add the files on

From your rails root directory:

  $ rails generate formtastic_validation

This adds a configuration file to config/initializers and a couple of javascript files to public/javascripts

After that you need to add this to your application layout

  <head>
    <%= javascript_include_tag 'livevalidation-1.3.min' %>
    <%= javascript_include_tag 'formtastic_validation-0.1.4.min' %>
    <script type="text/javascript">
      function initialize() {
          var formtasticValidation = new FormtasticValidation;
          formtasticValidation.initialize();
      }
    </script>
  </head>
  <body onload="initialize()">
  </body>

What the above does:

  • it included the livevalidation and formtastic_validation javascript files
  • it ran a function that instantiates a FormatasticValidation object and let it call initialize()

Usage

There is nothing to change in your existing code. You should see “Thankyou!” appearing next to fields which passed the validations. Forms which do not fufil the validations will fail to submit.

Validation options work.

Configuration

The valid message can be changed in the formtastic_validation configuration file under config/initializers

CSS Styling

You can style the validation messages with the css selectors

.LV_validation_message { ... }   /* the validation message */
.LV_valid { ... }                /* for valid messages */
.LV_invalid { ... }              /* for invalid messages */

Compatibility

This gem is Rails 2 and 3 compatible.

Upgrading

Existing users need not change anything from the upgrade from rails 2 to 3.

Caveats

Only the following validations work:

  1. validates_presence_of
  2. validates_acceptance_of
  3. validates_confirmation_of
  4. validates_exclusion_of
  5. validates_inclusion_of
  6. validates_numericality_of
  7. validates_format_of
  8. validates_length_of

validates_size_of does not work. Do use my fork of the validation_reflection gem for it to work.

The rest do not work as they depend on server queries.

Alternative implementations

http://github.com/dnclabs/client_side_validations
http://github.com/grimen/validatious-on-rails

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don’t break it in a
    future version unintentionally.
  • Commit, do not mess with rakefile, version, or history.
    (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Wong Liang Zan. See LICENSE for details.

formtastic_validation's People

Contributors

liangzan avatar qnm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

formtastic_validation's Issues

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.