client_side_validations 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -314,6 +314,7 @@ var clientSideValidations = {
314
314
  element.before(inputErrorField);
315
315
  inputErrorField.find('span#input_tag').replaceWith(element);
316
316
  inputErrorField.find('label.message').attr('for', element.attr('id'));
317
+ labelErrorField.find('label.message').attr('for', element.attr('id'));
317
318
  label.replaceWith(labelErrorField);
318
319
  labelErrorField.find('label#label_tag').replaceWith(label);
319
320
  }
@@ -15,16 +15,20 @@ module ClientSideValidations::ActionView::Helpers
15
15
  end
16
16
 
17
17
  base.class_eval do
18
- alias_method_chain :initialize, :client_side_validations
19
- alias_method_chain :fields_for, :client_side_validations
20
- alias_method_chain :check_box, :client_side_validations
21
- alias_method_chain :radio_button, :client_side_validations
18
+ alias_method_chain :initialize, :client_side_validations
19
+ alias_method_chain :fields_for, :client_side_validations
20
+ alias_method_chain :check_box, :client_side_validations
21
+ alias_method_chain :radio_button, :client_side_validations
22
+ alias_method_chain :select, :client_side_validations
23
+ alias_method_chain :collection_select, :client_side_validations
24
+ alias_method_chain :grouped_collection_select, :client_side_validations
25
+ alias_method_chain :time_zone_select, :client_side_validations
22
26
 
23
27
  def self.client_side_form_settings(options, form_helper)
24
28
  {
25
29
  :type => self.to_s,
26
30
  :input_tag => form_helper.class.field_error_proc.call(%{<span id="input_tag" />}, Struct.new(:error_message, :tag_id).new([], "")),
27
- :label_tag => form_helper.class.field_error_proc.call(%{<label id="label_tag" />})
31
+ :label_tag => form_helper.class.field_error_proc.call(%{<label id="label_tag" />}, Struct.new(:error_message, :tag_id).new([], ""))
28
32
  }
29
33
  end
30
34
  end
@@ -51,6 +55,26 @@ module ClientSideValidations::ActionView::Helpers
51
55
  radio_button_without_client_side_validations(method, tag_value, options)
52
56
  end
53
57
 
58
+ def select_with_client_side_validations(method, choices, options = {}, html_options = {})
59
+ apply_client_side_validators(method, html_options)
60
+ select_without_client_side_validations(method, choices, options, html_options)
61
+ end
62
+
63
+ def collection_select_with_client_side_validations(method, collection, value_method, text_method, options = {}, html_options = {})
64
+ apply_client_side_validators(method, html_options)
65
+ collection_select_without_client_side_validations(method, collection, value_method, text_method, options, html_options)
66
+ end
67
+
68
+ def grouped_collection_select_with_client_side_validations(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
69
+ apply_client_side_validators(method, html_options)
70
+ grouped_collection_select_without_client_side_validations(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
71
+ end
72
+
73
+ def time_zone_select_with_client_side_validations(method, priority_zones = nil, options = {}, html_options = {})
74
+ apply_client_side_validators(method, html_options)
75
+ time_zone_select_without_client_side_validations(method, priority_zones = nil, options, html_options)
76
+ end
77
+
54
78
  private
55
79
 
56
80
  def apply_client_side_validators(method, options = {})
@@ -17,7 +17,7 @@ module ClientSideValidations::ActiveRecord
17
17
  relation = t[attribute].matches(value)
18
18
  end
19
19
 
20
- relation = relation.and(t[:id].not_eq(params[:id])) if params[:id]
20
+ relation = relation.and(t.primary_key.not_eq(params[:id])) if params[:id]
21
21
 
22
22
  (params[:scope] || {}).each do |key, value|
23
23
  relation = relation.and(t[key].eq(value))
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = "3.0.3"
2
+ VERSION = "3.0.4"
3
3
  end
@@ -283,5 +283,55 @@ class ClientSideValidations::ActionViewHelpersTest < ActionView::TestCase
283
283
  end
284
284
  assert_equal expected, output_buffer
285
285
  end
286
+
287
+ def test_select
288
+ form_for(@post, :validate => true) do |f|
289
+ concat f.select(:cost, [])
290
+ end
291
+
292
+ validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
293
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
294
+ %{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
295
+ end
296
+ assert_equal expected, output_buffer
297
+ end
298
+
299
+ def test_collection_select
300
+ form_for(@post, :validate => true) do |f|
301
+ concat f.collection_select(:cost, [], :id, :name)
302
+ end
303
+
304
+ validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
305
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
306
+ %{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
307
+ end
308
+ assert_equal expected, output_buffer
309
+ end
310
+
311
+ def test_grouped_collection_select
312
+ form_for(@post, :validate => true) do |f|
313
+ concat f.grouped_collection_select(:cost, [], :group_method, :group_label_method, :id, :name)
314
+ end
315
+
316
+ validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
317
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
318
+ %{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
319
+ end
320
+ assert_equal expected, output_buffer
321
+ end
322
+
323
+ def test_time_zone_select
324
+ zones = mock('TimeZones')
325
+ zones.stubs(:all).returns([])
326
+ form_for(@post, :validate => true) do |f|
327
+ concat f.time_zone_select(:cost, nil, :model => zones)
328
+ end
329
+
330
+ validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
331
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
332
+ %{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
333
+ end
334
+ assert_equal expected, output_buffer
335
+ end
286
336
  end
287
337
 
@@ -157,4 +157,50 @@ class ClientSideValidations::LegacyActionViewHelpersTest < ActionView::TestCase
157
157
  assert_equal expected, result
158
158
  end
159
159
 
160
+ def test_select
161
+ form_for(@post) do |f|
162
+ concat f.select(:cost, [])
163
+ end
164
+
165
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
166
+ %{<select id="post_cost" name="post[cost]"></select>}
167
+ end
168
+ assert_equal expected, output_buffer
169
+ end
170
+
171
+ def test_collection_select
172
+ form_for(@post) do |f|
173
+ concat f.collection_select(:cost, [], :id, :name)
174
+ end
175
+
176
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
177
+ %{<select id="post_cost" name="post[cost]"></select>}
178
+ end
179
+ assert_equal expected, output_buffer
180
+ end
181
+
182
+ def test_grouped_collection_select
183
+ form_for(@post) do |f|
184
+ concat f.grouped_collection_select(:cost, [], :group_method, :group_label_method, :id, :name)
185
+ end
186
+
187
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
188
+ %{<select id="post_cost" name="post[cost]"></select>}
189
+ end
190
+ assert_equal expected, output_buffer
191
+ end
192
+
193
+ def test_time_zone_select
194
+ zones = mock('TimeZones')
195
+ zones.stubs(:all).returns([])
196
+ form_for(@post) do |f|
197
+ concat f.time_zone_select(:cost, nil, :model => zones)
198
+ end
199
+
200
+ expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
201
+ %{<select id="post_cost" name="post[cost]"></select>}
202
+ end
203
+ assert_equal expected, output_buffer
204
+ end
160
205
  end
206
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.0.3
5
+ version: 3.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Cardarella
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-18 00:00:00 -04:00
13
+ date: 2011-04-21 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency