Skip to content

Commit

Permalink
Fixed:
Browse files Browse the repository at this point in the history
numericality: greater_than
numericality: less_than
  • Loading branch information
bcardarella committed Sep 1, 2010
1 parent 1ba2118 commit 268f3d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client_side_validations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brian Cardarella"]
s.date = %q{2010-08-31}
s.date = %q{2010-09-01}
s.description = %q{Client Side Validations for Rails 2.x and 3.x}
s.email = %q{bcardarella@gmail.com}
s.extra_rdoc_files = [
Expand Down
8 changes: 8 additions & 0 deletions javascript/lib/client_side_validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ jQuery.validator.addMethod("numericality", function(value, element) {
return this.optional(element) || /^(\d+(\.|,)\d+|\d+)$/.test(value);
}, jQuery.validator.format("Is not a number."));

jQuery.validator.addMethod("greater_than", function(value, element, params) {
return this.optional(element) || parseFloat(value) > params;
}, jQuery.validator.format("Wrong number."));

jQuery.validator.addMethod("less_than", function(value, element, params) {
return this.optional(element) || parseFloat(value) < params;
}, jQuery.validator.format("Wrong number."));

jQuery.validator.addMethod("odd", function(value, element) {
return this.optional(element) || parseInt(value) % 2 == 1;
}, jQuery.validator.format("Must be odd."));
Expand Down
8 changes: 7 additions & 1 deletion lib/client_side_validations/orm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ def extract_rules(validations, field = nil)
validations.each do |kind, options|
kind = convert_kind(kind, options)
value = case kind
when 'acceptance', 'required', 'digits', 'numericality', 'greater_than', 'min', 'less_than', 'max', 'odd', 'even', 'confirmation'
when 'acceptance', 'required', 'digits', 'numericality', 'odd', 'even', 'confirmation'
true
when 'greater_than', 'less_than'
options[kind]
when 'max'
options['less_than_or_equal_to']
when 'min'
options['greater_than_or_equal_to']
when 'format'
options['with']
when 'exclusion', 'inclusion'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
end

it 'should translate the rule' do
@result['rules']['number']['min'].should be_true
@result['rules']['number']['min'].should == 5
@result['rules']['number']['required'].should be_true
@result['rules']['number']['numericality'].should be_true
end
Expand All @@ -141,7 +141,7 @@
end

it 'should translate the rule' do
@result['rules']['number']['less_than'].should be_true
@result['rules']['number']['less_than'].should == 5
@result['rules']['number']['required'].should be_true
@result['rules']['number']['numericality'].should be_true
end
Expand All @@ -165,7 +165,7 @@
end

it 'should translate the rule' do
@result['rules']['number']['max'].should be_true
@result['rules']['number']['max'].should == 5
@result['rules']['number']['required'].should be_true
@result['rules']['number']['numericality'].should be_true
end
Expand Down

0 comments on commit 268f3d5

Please sign in to comment.