Happyformvalidator

A simple ready made form validator for use within coffeescript

Installation

Add this line to your application's Gemfile:

gem 'happyformvalidator'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install happyformvalidator

Usage

in application.js you need:

//=require happyformvalidator

From within a coffeescript file you can validate stuff like this:

form_validator = new FormValidator()

$("#update_account_form").submit ->
  check_account_form()

check_account_form = ->
  email = $("#account_email")
  nickname = $("#account_username")
  first_name = $("#account_first_name")
  last_name = $("#account_last_name")

  form_is_valid = false
  form_is_valid = form_validator.validate_passwords_match($("#account_new_password"), $("#account_confirm_password"))
  form_is_valid = form_is_valid && form_validator.validate_email email
  form_is_valid = form_is_valid && form_validator.validate_presence_of nickname, "Please enter your username"
  form_is_valid = form_is_valid && form_validator.validate_presence_of first_name, "Please enter your first name"
  form_is_valid = form_is_valid && form_validator.validate_presence_of last_name, "Please enter your last name"

  form_is_valid 

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request