client_side_validations 3.2.5 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 315d850e3c4c93019d3cf6e4052e33e72c3aad67
4
- data.tar.gz: 9a3d22a1a8ebd7aba6bbaa93c96cdc848e67927e
3
+ metadata.gz: 45901353d1622b2e772baa28710eba7455927cf2
4
+ data.tar.gz: 1029d710ab65f47ad806ed3509948586882d0e92
5
5
  SHA512:
6
- metadata.gz: 4ee962238c0d65d24649fad3aa8cf2cf9369e0c285efe361a3d56ebc5204b8e1d73f8d299e58ebacf97985215b11ca147e64cff1a615523dc4e993a1664198ac
7
- data.tar.gz: ec6dddc31912eda921f7c732aa99514b8d5fdce31afa07b4ad1407f5e38b8580314b4c1cb3b45625a776c55cf503292b0be90129da83162e02cb73f63c1b94de
6
+ metadata.gz: 6f02c2df76f05b36265271ba582bc35cd0fd38859c72f1b96a002a012c8017750d8efa4563d8262dd44cd595cebfb55f5defe2240fd8a9b3f1e3cf1597b5c762
7
+ data.tar.gz: 79bbcab6259cdcecbbca630b2557575e229ce7fb8123aaa64c61a6d5887a8b9d9bf7736ddc9acb8b507413761a9d6a200eecd8a467e294cb9c7db6bccb59bd2c
@@ -27,6 +27,4 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'json'
28
28
  s.add_development_dependency 'coffee-script'
29
29
  s.add_development_dependency 'jquery-rails'
30
-
31
- s.add_development_dependency 'coveralls'
32
30
  end
@@ -95,7 +95,7 @@ module ClientSideValidations::ActionView::Helpers
95
95
  if @options[:validate]
96
96
  index = @default_options[:index].present? ? "[#{@default_options[:index]}]" : ''
97
97
  name = options[:name] || "#{@object_name}#{index}[#{method}]"
98
- child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index])})" : "\\d+"
98
+ child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index].to_s)})" : "\\d+"
99
99
  name = name.to_s.gsub(/_attributes\]\[#{child_index}\]/, '_attributes][]')
100
100
  name = "#{name}#{options[:multiple] ? "[]" : nil}"
101
101
  @options[:validators][@object][method] = { :name => name, :options => options[:validate] }
@@ -128,7 +128,7 @@ module ClientSideValidations::ActionView::Helpers
128
128
  end
129
129
 
130
130
  if ClientSideValidations::Config.number_format_with_locale and defined?(I18n)
131
- number_format = I18n.t("number.format").extract!(:separator, :delimiter)
131
+ number_format = I18n.t("number.format").slice(:separator, :delimiter)
132
132
  else
133
133
  number_format = {:separator=>".", :delimiter=>","}
134
134
  end
@@ -136,7 +136,7 @@ module ClientSideValidations::ActionView::Helpers
136
136
 
137
137
 
138
138
  content_tag(:script) do
139
- "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path||"").sub(/\/+\Z/,'')}';if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators => 'validator_hash').to_json};\n//]]>".html_safe
139
+ "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};#{"if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path).sub(/\/+\Z/,'')}';" if ClientSideValidations::Config.root_path.present? }if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators => 'validator_hash').to_json};\n//]]>".html_safe
140
140
  end
141
141
  end
142
142
  end
@@ -6,16 +6,19 @@ module ClientSideValidations::ActiveRecord
6
6
  hash[:case_sensitive] = options[:case_sensitive]
7
7
  hash[:id] = model.id unless model.new_record?
8
8
  hash[:allow_blank] = true if options[:allow_blank]
9
+
10
+ if options.key?(:client_validations) && options[:client_validations].key?(:class)
11
+ hash[:class] = options[:client_validations][:class].underscore
12
+ elsif model.class.name.demodulize != model.class.name
13
+ hash[:class] = model.class.name.underscore
14
+ end
15
+
9
16
  if options.key?(:scope) && options[:scope].present?
10
17
  hash[:scope] = Array.wrap(options[:scope]).inject({}) do |scope_hash, scope_item|
11
18
  scope_hash.merge!(scope_item => model.send(scope_item))
12
19
  end
13
20
  end
14
21
 
15
- unless model.class.name.demodulize == model.class.name
16
- hash[:class] = model.class.name.underscore
17
- end
18
-
19
22
  hash
20
23
  end
21
24
 
@@ -11,16 +11,32 @@ module ClientSideValidations
11
11
  end
12
12
 
13
13
  def call(env)
14
- if matches = /^\/validators\/(\w+)$/.match(env['PATH_INFO'])
15
- if ClientSideValidations::Config.disabled_validators.include?(matches[1].to_sym)
16
- [500, {'Content-Type' => 'application/json', 'Content-Length' => '0'}, ['']]
17
- else
18
- "::ClientSideValidations::Middleware::#{matches[1].camelize}".constantize.new(env).response
19
- end
14
+ if matches = /\A\/validators\/(\w+)\z/.match(env['PATH_INFO'])
15
+ process_request(matches.captures.first, env)
20
16
  else
21
17
  @app.call(env)
22
18
  end
23
19
  end
20
+
21
+ def process_request(validation, env)
22
+ if disabled_validators.include?(validation)
23
+ error_resp
24
+ else
25
+ klass_name = validation.camelize
26
+ klass_name = "::ClientSideValidations::Middleware::#{klass_name}"
27
+ klass_name.constantize.new(env).response
28
+ end
29
+ rescue => e
30
+ error_resp
31
+ end
32
+
33
+ def disabled_validators
34
+ ClientSideValidations::Config.disabled_validators.map(&:to_s)
35
+ end
36
+
37
+ def error_resp
38
+ [500, {'Content-Type' => 'application/json', 'Content-Length' => '0'}, ['']]
39
+ end
24
40
  end
25
41
 
26
42
  class Base
@@ -109,8 +125,8 @@ module ClientSideValidations
109
125
 
110
126
  def extract_resources
111
127
  parent_key = (request.params.keys - IGNORE_PARAMS).first
112
-
113
- if nested?(request.params[parent_key], 1)
128
+
129
+ if nested?(request.params[parent_key], 1)
114
130
  klass, attribute, value = uproot(request.params[parent_key])
115
131
  klass = klass.classify.constantize
116
132
  else
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = '3.2.5'
2
+ VERSION = '3.2.6'
3
3
  end
@@ -7,6 +7,10 @@
7
7
  # ClientSideValidations::Config.number_format_with_locale = true
8
8
 
9
9
  # Uncomment the following block if you want each input field to have the validation messages attached.
10
+ #
11
+ # Note: client_side_validation requires the error to be encapsulated within
12
+ # <label for="#{instance.send(:tag_id)}" class="message"></label>
13
+ #
10
14
  # ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
11
15
  # unless html_tag =~ /^<label/
12
16
  # %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
@@ -44,7 +44,15 @@
44
44
  };
45
45
 
46
46
  validatorsFor = function(name, validators) {
47
- name = name.replace(/_attributes\]\[\w+\]\[(\w+)\]/g, "_attributes][][$1]");
47
+ var captures, validator, validator_name;
48
+ if (captures = name.match(/\[(\w+_attributes)\].*\[(\w+)\]$/)) {
49
+ for (validator_name in validators) {
50
+ validator = validators[validator_name];
51
+ if (validator_name.match("\\[" + captures[1] + "\\].*\\[\\]\\[" + captures[2] + "\\]$")) {
52
+ name = name.replace(/\[[\da-z_]+\]\[(\w+)\]$/g, "[][$1]");
53
+ }
54
+ }
55
+ }
48
56
  return validators[name] || {};
49
57
  };
50
58
 
@@ -562,7 +570,7 @@
562
570
  _results = [];
563
571
  for (validator in _ref) {
564
572
  func = _ref[validator];
565
- if (window.ClientSideValidations.disabled_validators.indexOf(validator) !== -1) {
573
+ if (__indexOf.call(window.ClientSideValidations.disabled_validators, validator) >= 0) {
566
574
  _results.push(delete window.ClientSideValidations.validators.remote[validator]);
567
575
  } else {
568
576
  _results.push(void 0);
@@ -576,7 +584,7 @@
576
584
  add: function(element, settings, message) {
577
585
  var form, inputErrorField, label, labelErrorField;
578
586
  form = $(element[0].form);
579
- if (element.data('valid') !== false && !(form.find("label.message[for='" + (element.attr('id')) + "']")[0] != null)) {
587
+ if (element.data('valid') !== false && (form.find("label.message[for='" + (element.attr('id')) + "']")[0] == null)) {
580
588
  inputErrorField = jQuery(settings.input_tag);
581
589
  labelErrorField = jQuery(settings.label_tag);
582
590
  label = form.find("label[for='" + (element.attr('id')) + "']:not(.message)");
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.5
4
+ version: 3.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-25 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: coveralls
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '>='
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
153
  description: Client Side Validations
168
154
  email:
169
155
  - bcardarella@gmail.com
@@ -221,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
207
  version: '0'
222
208
  requirements: []
223
209
  rubyforge_project:
224
- rubygems_version: 2.0.0
210
+ rubygems_version: 2.0.3
225
211
  signing_key:
226
212
  specification_version: 4
227
213
  summary: Client Side Validations