happyformvalidator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in happydatepicker.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Fabio Russo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Happyformvalidator
2
+
3
+ A simple ready made form validator for use within coffeescript
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'happyformvalidator'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install happyformvalidator
18
+
19
+ ## Usage
20
+
21
+ in application.js you need:
22
+
23
+ //=require happyformvalidator
24
+
25
+ From within a coffeescript file you can validate stuff like this:
26
+
27
+ form_validator = new FormValidator()
28
+
29
+ $("#update_account_form").submit ->
30
+ check_account_form()
31
+
32
+ check_account_form = ->
33
+ email = $("#account_email")
34
+ nickname = $("#account_username")
35
+ first_name = $("#account_first_name")
36
+ last_name = $("#account_last_name")
37
+
38
+ form_is_valid = false
39
+ form_is_valid = form_validator.validate_passwords_match($("#account_new_password"), $("#account_confirm_password"))
40
+ form_is_valid = form_is_valid && form_validator.validate_email email
41
+ form_is_valid = form_is_valid && form_validator.validate_presence_of nickname, "Please enter your username"
42
+ form_is_valid = form_is_valid && form_validator.validate_presence_of first_name, "Please enter your first name"
43
+ form_is_valid = form_is_valid && form_validator.validate_presence_of last_name, "Please enter your last name"
44
+
45
+ form_is_valid
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/happyformvalidator/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Fabio Russo"]
6
+ gem.email = ["fabio@objectivesheep.com"]
7
+ gem.platform = Gem::Platform::RUBY
8
+ gem.description = %q{A simple js form validation}
9
+ gem.summary = ""
10
+ gem.homepage = "http://objectivesheep.com"
11
+ gem.require_paths = ["lib"]
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.name = "happyformvalidator"
14
+ gem.version = Happyformvalidator::Rails::VERSION
15
+ gem.add_dependency "happyerrorsnotices", ">= 0.0.1"
16
+ end
@@ -0,0 +1,6 @@
1
+ module Happyformvalidator
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Happyformvalidator
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'happyformvalidator/rails/engine'
2
+ require 'happyformvalidator/rails/version'
3
+
4
+ module Happyformvalidator
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'happyformvalidator/rails'
@@ -0,0 +1,52 @@
1
+ class @FormValidator
2
+
3
+ constructor: ->
4
+ @errors = new Errors
5
+ @show_errors = true
6
+
7
+ validate_presence_of: (field_name, message) ->
8
+ isValid = true
9
+ if field_name.val() is "" or field_name.val() == field_name.attr('placeholder')
10
+ if @show_errors
11
+ @errors.setErrorMessage message
12
+ isValid = false
13
+ isValid
14
+
15
+ validate_email: (emailAddress) ->
16
+ isValid = true
17
+ if emailAddress.val() is "" or emailAddress.val() == emailAddress.attr('placeholder')
18
+ if @show_errors
19
+ @errors.setErrorMessage "Please enter your email"
20
+ isValid = false
21
+ else
22
+ pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i)
23
+ isValid = pattern.test(emailAddress.val())
24
+ if @show_errors
25
+ @errors.setErrorMessage "Please enter a valid email address" unless isValid
26
+ isValid
27
+
28
+ validate_password: (pwd) ->
29
+ if pwd.val() is "" or pwd.val() == pwd.attr('placeholder')
30
+ if @show_errors
31
+ @errors.setErrorMessage "Please enter a password"
32
+ isValid = false
33
+ else if pwd.val().length < 6
34
+ if @show_errors
35
+ @errors.setErrorMessage "Password should have at least 6 characters"
36
+ isValid = false
37
+
38
+ validate_passwords_match: (passwordField, confirmationField) ->
39
+ isValid = true
40
+ pwd = passwordField.val()
41
+ confirm = confirmationField.val()
42
+
43
+ unless pwd is confirm
44
+ if @show_errors
45
+ @errors.setErrorMessage "Passwords do not match"
46
+ isValid = false
47
+ isValid
48
+
49
+ class @SilentFormValidator extends FormValidator
50
+
51
+ constructor: ->
52
+ @show_errors = false
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: happyformvalidator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fabio Russo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: happyerrorsnotices
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.1
30
+ description: A simple js form validation
31
+ email:
32
+ - fabio@objectivesheep.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - happyformvalidator.gemspec
43
+ - lib/happyformvalidator.rb
44
+ - lib/happyformvalidator/rails.rb
45
+ - lib/happyformvalidator/rails/engine.rb
46
+ - lib/happyformvalidator/rails/version.rb
47
+ - vendor/assets/javascripts/happyformvalidator.js.coffee
48
+ homepage: http://objectivesheep.com
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: ''
72
+ test_files: []