client_side_validations 3.2.0 → 3.2.1

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.
@@ -93,7 +93,8 @@ module ClientSideValidations::ActionView::Helpers
93
93
 
94
94
  def build_validation_options(method, options = {})
95
95
  if @options[:validate]
96
- name = options[:name] || "#{@object_name}[#{method}]"
96
+ index = @default_options[:index].present? ? "[#{@default_options[:index]}]" : ''
97
+ name = options[:name] || "#{@object_name}#{index}[#{method}]"
97
98
  child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index])})" : "\\d+"
98
99
  name = name.to_s.gsub(/_attributes\]\[#{child_index}\]/, '_attributes][]')
99
100
  name = "#{name}#{options[:multiple] ? "[]" : nil}"
@@ -74,7 +74,11 @@ module ClientSideValidations::ActionView::Helpers
74
74
  option_hash.merge!(attr[0] => attr[1][:options])
75
75
  end
76
76
 
77
- validation_hash = object_opts[0].client_side_validation_hash(option_hash)
77
+ if object_opts[0].respond_to?(:client_side_validation_hash)
78
+ validation_hash = object_opts[0].client_side_validation_hash(option_hash)
79
+ else
80
+ validation_hash = {}
81
+ end
78
82
 
79
83
  option_hash.each_key do |attr|
80
84
  if validation_hash[attr]
@@ -16,7 +16,7 @@ module ClientSideValidations::ActiveModel
16
16
  hash[:only_integer] = true
17
17
  end
18
18
 
19
- hash[:allow_blank] = true if options[:allow_nil]
19
+ hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
20
20
 
21
21
  OPTION_MAP.each do |option, message_type|
22
22
  if count = options[option]
@@ -14,7 +14,7 @@ module ClientSideValidations::ActiveRecord
14
14
  t = klass.arel_table
15
15
 
16
16
  if params[:case_sensitive] == 'true'
17
- if t.engine.connection.instance_variable_get("@config")[:adapter] =~ /^mysql/
17
+ if t.engine.connection.adapter_name =~ /^mysql/i
18
18
  relation = Arel::Nodes::SqlLiteral.new("BINARY #{t[attribute].eq(value).to_sql}")
19
19
  else
20
20
  relation = t[attribute].eq(value)
@@ -24,9 +24,9 @@ module ClientSideValidations::ActiveRecord
24
24
  end
25
25
 
26
26
  if relation.is_a?(Arel::Nodes::SqlLiteral)
27
- relation = Arel::Nodes::SqlLiteral.new("BINARY #{t[attribute].eq(value).to_sql} AND #{t.primary_key.not_eq(params[:id]).to_sql}")
27
+ relation = Arel::Nodes::SqlLiteral.new("BINARY #{t[attribute].eq(value).to_sql} AND #{t[klass.primary_key].not_eq(params[:id]).to_sql}")
28
28
  else
29
- relation = relation.and(t.primary_key.not_eq(params[:id])) if params[:id]
29
+ relation = relation.and(t[klass.primary_key].not_eq(params[:id])) if params[:id]
30
30
  end
31
31
 
32
32
  (params[:scope] || {}).each do |attribute, value|
@@ -13,7 +13,7 @@ module ClientSideValidations
13
13
  def call(env)
14
14
  if matches = /^\/validators\/(\w+)$/.match(env['PATH_INFO'])
15
15
  if ClientSideValidations::Config.disabled_validators.include?(matches[1].to_sym)
16
- [500, {'Content-Type' => 'application/json', 'Content-Length' => 0}, ['']]
16
+ [500, {'Content-Type' => 'application/json', 'Content-Length' => '0'}, ['']]
17
17
  else
18
18
  "::ClientSideValidations::Middleware::#{matches[1].camelize}".constantize.new(env).response
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = '3.2.0'
2
+ VERSION = '3.2.1'
3
3
  end
@@ -9,22 +9,22 @@
9
9
  };
10
10
 
11
11
  $.fn.enableClientSideValidations = function() {
12
- this.filter('form[data-validate]').each(function() {
12
+ this.filter(ClientSideValidations.selectors.forms).each(function() {
13
13
  return ClientSideValidations.enablers.form(this);
14
14
  });
15
- return this.filter(':input:not(button)').each(function() {
15
+ return this.filter(ClientSideValidations.selectors.inputs).each(function() {
16
16
  return ClientSideValidations.enablers.input(this);
17
17
  });
18
18
  };
19
19
 
20
20
  $.fn.resetClientSideValidations = function() {
21
- return this.filter('form[data-validate]').each(function() {
21
+ return this.filter(ClientSideValidations.selectors.forms).each(function() {
22
22
  return ClientSideValidations.reset(this);
23
23
  });
24
24
  };
25
25
 
26
26
  $.fn.validate = function() {
27
- return this.filter('form[data-validate]').each(function() {
27
+ return this.filter(ClientSideValidations.selectors.forms).each(function() {
28
28
  return $(this).enableClientSideValidations();
29
29
  });
30
30
  };
@@ -115,7 +115,7 @@
115
115
  };
116
116
 
117
117
  $(function() {
118
- return $('form[data-validate]').validate();
118
+ return $(ClientSideValidations.selectors.forms).validate();
119
119
  });
120
120
 
121
121
  if (window.ClientSideValidations === void 0) {
@@ -126,6 +126,11 @@
126
126
  window.ClientSideValidations.forms = {};
127
127
  }
128
128
 
129
+ window.ClientSideValidations.selectors = {
130
+ inputs: ':input:not(button):not([type="submit"])[name]:visible:enabled',
131
+ forms: 'form[data-validate]'
132
+ };
133
+
129
134
  window.ClientSideValidations.reset = function(form) {
130
135
  var $form, key;
131
136
  $form = $(form);
@@ -190,7 +195,7 @@
190
195
  binding = _ref[event];
191
196
  $form.on(event, binding);
192
197
  }
193
- return $form.find(':input').each(function() {
198
+ return $form.find(ClientSideValidations.selectors.inputs).each(function() {
194
199
  return ClientSideValidations.enablers.input(this);
195
200
  });
196
201
  },
@@ -229,15 +234,15 @@
229
234
  };
230
235
  for (event in _ref) {
231
236
  binding = _ref[event];
232
- $input.filter(':enabled:not(:radio):not([id$=_confirmation]):visible:not(button)[name]').each(function() {
237
+ $input.filter(':not(:radio):not([id$=_confirmation])').each(function() {
233
238
  return $(this).attr('data-validate', true);
234
239
  }).on(event, binding);
235
240
  }
236
- $input.filter(':checkbox:visible').on('click.ClientSideValidations', function() {
241
+ $input.filter(':checkbox').on('click.ClientSideValidations', function() {
237
242
  $(this).isValid(form.ClientSideValidations.settings.validators);
238
243
  return true;
239
244
  });
240
- return $input.filter('[id$=_confirmation]:visible').each(function() {
245
+ return $input.filter('[id$=_confirmation]').each(function() {
241
246
  var confirmationElement, element, _ref1, _results;
242
247
  confirmationElement = $(this);
243
248
  element = $form.find("#" + (this.id.match(/(.+)_confirmation/)[1]) + ":input");
@@ -524,7 +529,8 @@
524
529
  if (jQuery.ajax({
525
530
  url: '/validators/uniqueness',
526
531
  data: data,
527
- async: false
532
+ async: false,
533
+ cache: false
528
534
  }).status === 200) {
529
535
  return options.message;
530
536
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -223,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  segments:
225
225
  - 0
226
- hash: 4066478814748043567
226
+ hash: -1004765606605133609
227
227
  required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  none: false
229
229
  requirements:
@@ -232,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
232
  version: '0'
233
233
  segments:
234
234
  - 0
235
- hash: 4066478814748043567
235
+ hash: -1004765606605133609
236
236
  requirements: []
237
237
  rubyforge_project:
238
238
  rubygems_version: 1.8.23