formtastic 2.1.1 → 2.2.0.rc
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.
- data/.gitignore +1 -0
- data/.travis.yml +19 -1
- data/Appraisals +7 -0
- data/CHANGELOG +18 -0
- data/README.textile +14 -16
- data/formtastic.gemspec +1 -1
- data/gemfiles/rails-4.gemfile +8 -0
- data/lib/formtastic/form_builder.rb +0 -1
- data/lib/formtastic/helpers/input_helper.rb +12 -26
- data/lib/formtastic/inputs.rb +6 -0
- data/lib/formtastic/inputs/base.rb +16 -4
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +17 -17
- data/lib/formtastic/inputs/base/wrapping.rb +25 -20
- data/lib/formtastic/inputs/boolean_input.rb +24 -1
- data/lib/formtastic/inputs/date_input.rb +5 -29
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_input.rb +6 -8
- data/lib/formtastic/inputs/datetime_picker_input.rb +100 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/select_input.rb +2 -5
- data/lib/formtastic/inputs/time_input.rb +4 -28
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +34 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +0 -8
- data/sample/basic_inputs.html +21 -1
- data/spec/builder/semantic_fields_for_spec.rb +1 -1
- data/spec/generators/formtastic/install/install_generator_spec.rb +1 -1
- data/spec/helpers/input_helper_spec.rb +20 -16
- data/spec/helpers/semantic_errors_helper_spec.rb +10 -10
- data/spec/inputs/custom_input_spec.rb +5 -2
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/{date_input_spec.rb → date_select_input_spec.rb} +34 -34
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/{datetime_input_spec.rb → datetime_select_input_spec.rb} +33 -33
- data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
- data/spec/inputs/hidden_input_spec.rb +21 -17
- data/spec/inputs/include_blank_spec.rb +3 -3
- data/spec/inputs/label_spec.rb +1 -1
- data/spec/inputs/placeholder_spec.rb +1 -1
- data/spec/inputs/select_input_spec.rb +22 -14
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/{time_input_spec.rb → time_select_input_spec.rb} +35 -35
- data/spec/spec_helper.rb +25 -1
- data/spec/support/custom_macros.rb +2 -2
- metadata +32 -21
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'time input' do
|
4
|
+
describe 'time select input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -19,7 +19,7 @@ describe 'time input' do
|
|
19
19
|
describe "with :ignore_date => true" do
|
20
20
|
before do
|
21
21
|
concat(semantic_form_for(@new_post) do |builder|
|
22
|
-
concat(builder.input(:publish_at, :as => :
|
22
|
+
concat(builder.input(:publish_at, :as => :time_select, :ignore_date => true))
|
23
23
|
end)
|
24
24
|
end
|
25
25
|
|
@@ -40,7 +40,7 @@ describe 'time input' do
|
|
40
40
|
before do
|
41
41
|
@new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
|
42
42
|
concat(semantic_form_for(@new_post) do |builder|
|
43
|
-
concat(builder.input(:publish_at, :as => :
|
43
|
+
concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
|
44
44
|
end)
|
45
45
|
end
|
46
46
|
|
@@ -59,7 +59,7 @@ describe 'time input' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should associate the legend label with the hour select' do
|
62
|
-
output_buffer.should have_tag('form li.
|
62
|
+
output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -68,7 +68,7 @@ describe 'time input' do
|
|
68
68
|
before do
|
69
69
|
@new_post.stub(:publish_at)
|
70
70
|
concat(semantic_form_for(@new_post) do |builder|
|
71
|
-
concat(builder.input(:publish_at, :as => :
|
71
|
+
concat(builder.input(:publish_at, :as => :time_select, :ignore_date => false))
|
72
72
|
end)
|
73
73
|
end
|
74
74
|
|
@@ -94,58 +94,58 @@ describe 'time input' do
|
|
94
94
|
describe "without seconds" do
|
95
95
|
before do
|
96
96
|
concat(semantic_form_for(@new_post) do |builder|
|
97
|
-
concat(builder.input(:publish_at, :as => :
|
97
|
+
concat(builder.input(:publish_at, :as => :time_select))
|
98
98
|
end)
|
99
99
|
end
|
100
100
|
|
101
|
-
it_should_have_input_wrapper_with_class("
|
101
|
+
it_should_have_input_wrapper_with_class("time_select")
|
102
102
|
it_should_have_input_wrapper_with_class(:input)
|
103
103
|
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
104
104
|
it_should_have_a_nested_fieldset
|
105
105
|
it_should_have_a_nested_fieldset_with_class('fragments')
|
106
106
|
it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
107
|
-
it_should_apply_error_logic_for_input_type(:
|
107
|
+
it_should_apply_error_logic_for_input_type(:time_select)
|
108
108
|
|
109
109
|
it 'should have a legend and label with the label text inside the fieldset' do
|
110
|
-
output_buffer.should have_tag('form li.
|
110
|
+
output_buffer.should have_tag('form li.time_select fieldset legend.label label', /Publish at/)
|
111
111
|
end
|
112
112
|
|
113
113
|
it 'should associate the legend label with the first select' do
|
114
|
-
output_buffer.should have_tag('form li.
|
114
|
+
output_buffer.should have_tag('form li.time_select fieldset legend.label label[@for="post_publish_at_4i"]')
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should have an ordered list of two items inside the fieldset' do
|
118
|
-
output_buffer.should have_tag('form li.
|
119
|
-
output_buffer.should have_tag('form li.
|
118
|
+
output_buffer.should have_tag('form li.time_select fieldset ol.fragments-group')
|
119
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li.fragment', :count => 2)
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should have five labels for hour and minute' do
|
123
|
-
output_buffer.should have_tag('form li.
|
124
|
-
output_buffer.should have_tag('form li.
|
125
|
-
output_buffer.should have_tag('form li.
|
123
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 2)
|
124
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
|
125
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'should have two selects for hour and minute' do
|
129
|
-
output_buffer.should have_tag('form li.
|
129
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 2)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
describe "with seconds" do
|
134
134
|
before do
|
135
135
|
concat(semantic_form_for(@new_post) do |builder|
|
136
|
-
concat(builder.input(:publish_at, :as => :
|
136
|
+
concat(builder.input(:publish_at, :as => :time_select, :include_seconds => true))
|
137
137
|
end)
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'should have five labels for hour and minute' do
|
141
|
-
output_buffer.should have_tag('form li.
|
142
|
-
output_buffer.should have_tag('form li.
|
143
|
-
output_buffer.should have_tag('form li.
|
144
|
-
output_buffer.should have_tag('form li.
|
141
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => 3)
|
142
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /hour/i)
|
143
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /minute/i)
|
144
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /second/i)
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should have three selects for hour, minute and seconds' do
|
148
|
-
output_buffer.should have_tag('form li.
|
148
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li', :count => 3)
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'should generate a sanitized label and matching ids for attribute' do
|
@@ -163,40 +163,40 @@ describe 'time input' do
|
|
163
163
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
164
164
|
output_buffer.replace ''
|
165
165
|
concat(semantic_form_for(@new_post) do |builder|
|
166
|
-
concat(builder.input(:created_at, :as => :
|
166
|
+
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
167
167
|
end)
|
168
|
-
output_buffer.should have_tag('form li.
|
168
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length)
|
169
169
|
fields.each do |f|
|
170
|
-
output_buffer.should have_tag('form li.
|
170
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
175
175
|
output_buffer.replace ''
|
176
176
|
concat(semantic_form_for(@new_post) do |builder|
|
177
|
-
concat(builder.input(:created_at, :as => :
|
177
|
+
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => "" }))
|
178
178
|
end)
|
179
|
-
output_buffer.should have_tag('form li.
|
179
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
180
180
|
fields.each do |f|
|
181
|
-
output_buffer.should have_tag('form li.
|
181
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should not render the label when :labels[:#{field}] is false" do
|
186
186
|
output_buffer.replace ''
|
187
187
|
concat(semantic_form_for(@new_post) do |builder|
|
188
|
-
concat(builder.input(:created_at, :as => :
|
188
|
+
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
189
189
|
end)
|
190
|
-
output_buffer.should have_tag('form li.
|
190
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', :count => fields.length-1)
|
191
191
|
fields.each do |f|
|
192
|
-
output_buffer.should have_tag('form li.
|
192
|
+
output_buffer.should have_tag('form li.time_select fieldset ol li label', /#{f}/i) unless field == f
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
197
197
|
output_buffer.replace ''
|
198
198
|
concat(semantic_form_for(@new_post) do |builder|
|
199
|
-
concat(builder.input(:created_at, :as => :
|
199
|
+
concat(builder.input(:created_at, :as => :time_select, :include_seconds => true, :labels => { field => false }))
|
200
200
|
end)
|
201
201
|
output_buffer.should_not include(">")
|
202
202
|
end
|
@@ -207,7 +207,7 @@ describe 'time input' do
|
|
207
207
|
describe ':namespace option' do
|
208
208
|
before do
|
209
209
|
concat(semantic_form_for(@new_post, :namespace => 'form2') do |builder|
|
210
|
-
concat(builder.input(:publish_at, :as => :
|
210
|
+
concat(builder.input(:publish_at, :as => :time_select))
|
211
211
|
end)
|
212
212
|
end
|
213
213
|
|
@@ -222,7 +222,7 @@ describe 'time input' do
|
|
222
222
|
it "should add the required attribute to the input's html options" do
|
223
223
|
with_config :use_required_attribute, true do
|
224
224
|
concat(semantic_form_for(@new_post) do |builder|
|
225
|
-
concat(builder.input(:title, :as => :
|
225
|
+
concat(builder.input(:title, :as => :time_select, :required => true))
|
226
226
|
end)
|
227
227
|
output_buffer.should have_tag("select[@required]", :count => 2)
|
228
228
|
end
|
@@ -234,7 +234,7 @@ describe 'time input' do
|
|
234
234
|
before do
|
235
235
|
concat(semantic_form_for(@new_post) do |builder|
|
236
236
|
concat(builder.fields_for(:author, :index => 3) do |author|
|
237
|
-
concat(author.input(:created_at, :as => :
|
237
|
+
concat(author.input(:created_at, :as => :time_select))
|
238
238
|
end)
|
239
239
|
end)
|
240
240
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -413,7 +413,31 @@ module FormtasticSpecHelper
|
|
413
413
|
yield
|
414
414
|
Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
|
415
415
|
end
|
416
|
-
|
416
|
+
|
417
|
+
class ToSMatcher
|
418
|
+
def initialize(str)
|
419
|
+
@str=str.to_s
|
420
|
+
end
|
421
|
+
|
422
|
+
def matches?(value)
|
423
|
+
value.to_s==@str
|
424
|
+
end
|
425
|
+
|
426
|
+
def failure_message_for_should
|
427
|
+
"Expected argument that converted to #{@str}"
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
def errors_matcher(method)
|
432
|
+
# In edge rails (Rails 4) tags store method_name as a string and index the errors object using a string
|
433
|
+
# therefore allow stubs to match on either string or symbol. The errors object calls to_sym on all index
|
434
|
+
# accesses so @object.errors[:abc] is equivalent to @object.errors["abc"]
|
435
|
+
if Rails::VERSION::MAJOR == 4
|
436
|
+
ToSMatcher.new(method)
|
437
|
+
else
|
438
|
+
method
|
439
|
+
end
|
440
|
+
end
|
417
441
|
end
|
418
442
|
|
419
443
|
::ActiveSupport::Deprecation.silenced = false
|
@@ -177,9 +177,9 @@ module CustomMacros
|
|
177
177
|
before do
|
178
178
|
@title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
|
179
179
|
@errors = mock('errors')
|
180
|
-
@errors.stub!(:[]).with(:title).and_return(@title_errors)
|
180
|
+
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
|
181
181
|
Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
|
182
|
-
@errors.stub!(:[]).with("title_#{suffix}".to_sym).and_return(nil)
|
182
|
+
@errors.stub!(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
|
183
183
|
end
|
184
184
|
@new_post.stub!(:errors).and_return(@errors)
|
185
185
|
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1676882131
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
- rc
|
11
|
+
version: 2.2.0.rc
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Justin French
|
@@ -15,8 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2012-03-
|
19
|
-
default_executable:
|
19
|
+
date: 2012-03-27 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: actionpack
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
hash: 7
|
30
30
|
segments:
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- gemfiles/rails-3.0.gemfile
|
227
227
|
- gemfiles/rails-3.1.gemfile
|
228
228
|
- gemfiles/rails-3.2.gemfile
|
229
|
+
- gemfiles/rails-4.gemfile
|
229
230
|
- lib/formtastic.rb
|
230
231
|
- lib/formtastic/actions.rb
|
231
232
|
- lib/formtastic/actions/base.rb
|
@@ -238,7 +239,6 @@ files:
|
|
238
239
|
- lib/formtastic/helpers.rb
|
239
240
|
- lib/formtastic/helpers/action_helper.rb
|
240
241
|
- lib/formtastic/helpers/actions_helper.rb
|
241
|
-
- lib/formtastic/helpers/buttons_helper.rb
|
242
242
|
- lib/formtastic/helpers/errors_helper.rb
|
243
243
|
- lib/formtastic/helpers/fieldset_wrapper.rb
|
244
244
|
- lib/formtastic/helpers/file_column_detection.rb
|
@@ -254,6 +254,7 @@ files:
|
|
254
254
|
- lib/formtastic/inputs/base/choices.rb
|
255
255
|
- lib/formtastic/inputs/base/collections.rb
|
256
256
|
- lib/formtastic/inputs/base/database.rb
|
257
|
+
- lib/formtastic/inputs/base/datetime_pickerish.rb
|
257
258
|
- lib/formtastic/inputs/base/errors.rb
|
258
259
|
- lib/formtastic/inputs/base/fileish.rb
|
259
260
|
- lib/formtastic/inputs/base/grouped_collections.rb
|
@@ -272,7 +273,11 @@ files:
|
|
272
273
|
- lib/formtastic/inputs/check_boxes_input.rb
|
273
274
|
- lib/formtastic/inputs/country_input.rb
|
274
275
|
- lib/formtastic/inputs/date_input.rb
|
276
|
+
- lib/formtastic/inputs/date_picker_input.rb
|
277
|
+
- lib/formtastic/inputs/date_select_input.rb
|
275
278
|
- lib/formtastic/inputs/datetime_input.rb
|
279
|
+
- lib/formtastic/inputs/datetime_picker_input.rb
|
280
|
+
- lib/formtastic/inputs/datetime_select_input.rb
|
276
281
|
- lib/formtastic/inputs/email_input.rb
|
277
282
|
- lib/formtastic/inputs/file_input.rb
|
278
283
|
- lib/formtastic/inputs/hidden_input.rb
|
@@ -286,6 +291,8 @@ files:
|
|
286
291
|
- lib/formtastic/inputs/string_input.rb
|
287
292
|
- lib/formtastic/inputs/text_input.rb
|
288
293
|
- lib/formtastic/inputs/time_input.rb
|
294
|
+
- lib/formtastic/inputs/time_picker_input.rb
|
295
|
+
- lib/formtastic/inputs/time_select_input.rb
|
289
296
|
- lib/formtastic/inputs/time_zone_input.rb
|
290
297
|
- lib/formtastic/inputs/url_input.rb
|
291
298
|
- lib/formtastic/localized_string.rb
|
@@ -314,8 +321,6 @@ files:
|
|
314
321
|
- spec/generators/formtastic/install/install_generator_spec.rb
|
315
322
|
- spec/helpers/action_helper_spec.rb
|
316
323
|
- spec/helpers/actions_helper_spec.rb
|
317
|
-
- spec/helpers/buttons_helper_spec.rb
|
318
|
-
- spec/helpers/commit_button_helper_spec.rb
|
319
324
|
- spec/helpers/form_helper_spec.rb
|
320
325
|
- spec/helpers/input_helper_spec.rb
|
321
326
|
- spec/helpers/inputs_helper_spec.rb
|
@@ -326,8 +331,11 @@ files:
|
|
326
331
|
- spec/inputs/check_boxes_input_spec.rb
|
327
332
|
- spec/inputs/country_input_spec.rb
|
328
333
|
- spec/inputs/custom_input_spec.rb
|
329
|
-
- spec/inputs/
|
330
|
-
- spec/inputs/
|
334
|
+
- spec/inputs/date_picker_input_spec.rb
|
335
|
+
- spec/inputs/date_select_input_spec.rb
|
336
|
+
- spec/inputs/datetime_picker_input_spec.rb
|
337
|
+
- spec/inputs/datetime_select_input_spec.rb
|
338
|
+
- spec/inputs/deprecated_time_date_datetime_inputs_spec.rb
|
331
339
|
- spec/inputs/email_input_spec.rb
|
332
340
|
- spec/inputs/file_input_spec.rb
|
333
341
|
- spec/inputs/hidden_input_spec.rb
|
@@ -343,7 +351,8 @@ files:
|
|
343
351
|
- spec/inputs/select_input_spec.rb
|
344
352
|
- spec/inputs/string_input_spec.rb
|
345
353
|
- spec/inputs/text_input_spec.rb
|
346
|
-
- spec/inputs/
|
354
|
+
- spec/inputs/time_picker_input_spec.rb
|
355
|
+
- spec/inputs/time_select_input_spec.rb
|
347
356
|
- spec/inputs/time_zone_input_spec.rb
|
348
357
|
- spec/inputs/url_input_spec.rb
|
349
358
|
- spec/inputs/with_options_spec.rb
|
@@ -354,7 +363,6 @@ files:
|
|
354
363
|
- spec/support/deferred_garbage_collection.rb
|
355
364
|
- spec/support/deprecation.rb
|
356
365
|
- spec/support/test_environment.rb
|
357
|
-
has_rdoc: true
|
358
366
|
homepage: http://github.com/justinfrench/formtastic
|
359
367
|
licenses: []
|
360
368
|
|
@@ -384,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
384
392
|
requirements: []
|
385
393
|
|
386
394
|
rubyforge_project:
|
387
|
-
rubygems_version: 1.
|
395
|
+
rubygems_version: 1.8.18
|
388
396
|
signing_key:
|
389
397
|
specification_version: 3
|
390
398
|
summary: A Rails form builder plugin/gem with semantically rich and accessible markup
|
@@ -400,8 +408,6 @@ test_files:
|
|
400
408
|
- spec/generators/formtastic/install/install_generator_spec.rb
|
401
409
|
- spec/helpers/action_helper_spec.rb
|
402
410
|
- spec/helpers/actions_helper_spec.rb
|
403
|
-
- spec/helpers/buttons_helper_spec.rb
|
404
|
-
- spec/helpers/commit_button_helper_spec.rb
|
405
411
|
- spec/helpers/form_helper_spec.rb
|
406
412
|
- spec/helpers/input_helper_spec.rb
|
407
413
|
- spec/helpers/inputs_helper_spec.rb
|
@@ -412,8 +418,11 @@ test_files:
|
|
412
418
|
- spec/inputs/check_boxes_input_spec.rb
|
413
419
|
- spec/inputs/country_input_spec.rb
|
414
420
|
- spec/inputs/custom_input_spec.rb
|
415
|
-
- spec/inputs/
|
416
|
-
- spec/inputs/
|
421
|
+
- spec/inputs/date_picker_input_spec.rb
|
422
|
+
- spec/inputs/date_select_input_spec.rb
|
423
|
+
- spec/inputs/datetime_picker_input_spec.rb
|
424
|
+
- spec/inputs/datetime_select_input_spec.rb
|
425
|
+
- spec/inputs/deprecated_time_date_datetime_inputs_spec.rb
|
417
426
|
- spec/inputs/email_input_spec.rb
|
418
427
|
- spec/inputs/file_input_spec.rb
|
419
428
|
- spec/inputs/hidden_input_spec.rb
|
@@ -429,7 +438,8 @@ test_files:
|
|
429
438
|
- spec/inputs/select_input_spec.rb
|
430
439
|
- spec/inputs/string_input_spec.rb
|
431
440
|
- spec/inputs/text_input_spec.rb
|
432
|
-
- spec/inputs/
|
441
|
+
- spec/inputs/time_picker_input_spec.rb
|
442
|
+
- spec/inputs/time_select_input_spec.rb
|
433
443
|
- spec/inputs/time_zone_input_spec.rb
|
434
444
|
- spec/inputs/url_input_spec.rb
|
435
445
|
- spec/inputs/with_options_spec.rb
|
@@ -440,3 +450,4 @@ test_files:
|
|
440
450
|
- spec/support/deferred_garbage_collection.rb
|
441
451
|
- spec/support/deprecation.rb
|
442
452
|
- spec/support/test_environment.rb
|
453
|
+
has_rdoc:
|
@@ -1,310 +0,0 @@
|
|
1
|
-
module Formtastic
|
2
|
-
module Helpers
|
3
|
-
|
4
|
-
# ButtonsHelper encapsulates the responsibilties of the {#buttons} and {#commit_button} helpers
|
5
|
-
# for submitting forms.
|
6
|
-
#
|
7
|
-
# {#buttons} is used to wrap the form's button(s) and actions in a `<fieldset>` and `<ol>`,
|
8
|
-
# with each item in the list containing the markup representing a single button.
|
9
|
-
#
|
10
|
-
# {#buttons} is usually called with a block containing a single {#commit_button} call:
|
11
|
-
#
|
12
|
-
# <%= semantic_form_for @post do |f| %>
|
13
|
-
# ...
|
14
|
-
# <%= f.buttons do %>
|
15
|
-
# <%= f.commit_button
|
16
|
-
# <% end %>
|
17
|
-
# <% end %>
|
18
|
-
#
|
19
|
-
# The HTML output will be something like:
|
20
|
-
#
|
21
|
-
# <form class="formtastic" method="post" action="...">
|
22
|
-
# ...
|
23
|
-
# <fieldset class="buttons">
|
24
|
-
# <ol>
|
25
|
-
# <li class="commit button">
|
26
|
-
# <input type="submit" name="commit" value="Create Post" class="create">
|
27
|
-
# </li>
|
28
|
-
# </ol>
|
29
|
-
# </fieldset>
|
30
|
-
# </form>
|
31
|
-
#
|
32
|
-
# While this may seem slightly over-engineered, it is consistent with the way form inputs are
|
33
|
-
# handled, and makes room for other types of buttons and actions in future versions (such as
|
34
|
-
# cancel buttons or links, reset buttons and even alternate actions like 'save and continue
|
35
|
-
# editing').
|
36
|
-
#
|
37
|
-
# It's important to note that the `semantic_form_for` and {#buttons} blocks wrap the
|
38
|
-
# standard Rails `form_for` helper and form builder, so you have full access to every standard
|
39
|
-
# Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from
|
40
|
-
# Formtastic when it doesn't suit to create your own buttons, links and actions:
|
41
|
-
#
|
42
|
-
# <%= semantic_form_for @post do |f| %>
|
43
|
-
# ...
|
44
|
-
# <%= f.buttons do %>
|
45
|
-
# <li class="save">
|
46
|
-
# <%= f.submit "Save" %>
|
47
|
-
# <li>
|
48
|
-
# <li class="cancel-link">
|
49
|
-
# Or <%= link_to "Cancel", posts_url %>
|
50
|
-
# <li>
|
51
|
-
# <% end %>
|
52
|
-
# <% end %>
|
53
|
-
#
|
54
|
-
# There are many other syntax variations and arguments to customize your form. See the
|
55
|
-
# full documentation of {#buttons} and {#commit_button} for details.
|
56
|
-
#
|
57
|
-
# @deprecated ButtonsHelper will be removed after 2.1
|
58
|
-
module ButtonsHelper
|
59
|
-
include Formtastic::Helpers::FieldsetWrapper
|
60
|
-
include Formtastic::LocalizedString
|
61
|
-
|
62
|
-
# Creates a fieldset and ol tag wrapping for use around a set of buttons. It can be
|
63
|
-
# called either with a block (in which you can do the usual Rails form stuff, HTML, ERB, etc),
|
64
|
-
# or with a list of named buttons. These two examples are functionally equivalent:
|
65
|
-
#
|
66
|
-
# # With a block:
|
67
|
-
# <% semantic_form_for @post do |f| %>
|
68
|
-
# ...
|
69
|
-
# <% f.buttons do %>
|
70
|
-
# <%= f.commit_button %>
|
71
|
-
# <% end %>
|
72
|
-
# <% end %>
|
73
|
-
#
|
74
|
-
# # With a list of fields:
|
75
|
-
# <% semantic_form_for @post do |f| %>
|
76
|
-
# <%= f.buttons :commit %>
|
77
|
-
# <% end %>
|
78
|
-
#
|
79
|
-
# # Output:
|
80
|
-
# <form ...>
|
81
|
-
# <fieldset class="buttons">
|
82
|
-
# <ol>
|
83
|
-
# <li class="commit button">
|
84
|
-
# <input type="submit" ...>
|
85
|
-
# </li>
|
86
|
-
# </ol>
|
87
|
-
# </fieldset>
|
88
|
-
# </form>
|
89
|
-
#
|
90
|
-
# Only one type of named button is supported at this time (:commit), and it's assumed to be
|
91
|
-
# the default choice, so this is also functionally equivalent, but may change in the future:
|
92
|
-
#
|
93
|
-
# # With no args:
|
94
|
-
# <% semantic_form_for @post do |f| %>
|
95
|
-
# ...
|
96
|
-
# <%= f.buttons %>
|
97
|
-
# <% end %>
|
98
|
-
#
|
99
|
-
# While this may seem slightly over-engineered, it is consistent with the way form inputs are
|
100
|
-
# handled, and makes room for other types of buttons and actions in future versions (such as
|
101
|
-
# cancel buttons or links, reset buttons and even alternate actions like 'save and continue
|
102
|
-
# editing').
|
103
|
-
#
|
104
|
-
# All options except `:name` and `:title` are passed down to the fieldset as HTML
|
105
|
-
# attributes (`id`, `class`, `style`...). If provided, the `:name` or `:title` option is
|
106
|
-
# passed into a `<legend>` inside the `<fieldset>` to name the set of buttons.
|
107
|
-
#
|
108
|
-
# @example Quickly add button(s) to the form, accepting all default values, options and behaviors
|
109
|
-
# <% semantic_form_for @post do |f| %>
|
110
|
-
# ...
|
111
|
-
# <%= f.buttons %>
|
112
|
-
# <% end %>
|
113
|
-
#
|
114
|
-
# @example Specify which named buttons you want, accepting all default values, options and behaviors
|
115
|
-
# <% semantic_form_for @post do |f| %>
|
116
|
-
# ...
|
117
|
-
# <%= f.buttons :commit %>
|
118
|
-
# <% end %>
|
119
|
-
#
|
120
|
-
# @example Specify which named buttons you want, and name the fieldset
|
121
|
-
# <% semantic_form_for @post do |f| %>
|
122
|
-
# ...
|
123
|
-
# <%= f.buttons :commit, :name => "Actions" %>
|
124
|
-
# or
|
125
|
-
# <%= f.buttons :commit, :label => "Actions" %>
|
126
|
-
# <% end %>
|
127
|
-
#
|
128
|
-
# @example Get full control over the commit_button options
|
129
|
-
# <% semantic_form_for @post do |f| %>
|
130
|
-
# ...
|
131
|
-
# <%= f.buttons do %>
|
132
|
-
# <%= f.commit_button :label => "Go", :button_html => { :class => "pretty" :disable_with => "Wait..." }, :wrapper_html => { ... }
|
133
|
-
# <% end %>
|
134
|
-
# <% end %>
|
135
|
-
#
|
136
|
-
# @example Make your own custom buttons, links or actions with standard Rails helpers or HTML
|
137
|
-
# <% semantic_form_for @post do |f| %>
|
138
|
-
# ...
|
139
|
-
# <%= f.buttons do %>
|
140
|
-
# <li class="submit">
|
141
|
-
# <%= f.submit "Submit" %>
|
142
|
-
# </li>
|
143
|
-
# <li class="reset">
|
144
|
-
# <input type="reset" value="Reset">
|
145
|
-
# </li>
|
146
|
-
# <li class="cancel">
|
147
|
-
# <%= link_to "Cancel", posts_url %>
|
148
|
-
# </li>
|
149
|
-
# <% end %>
|
150
|
-
# <% end %>
|
151
|
-
#
|
152
|
-
# @example Add HTML attributes to the fieldset
|
153
|
-
# <% semantic_form_for @post do |f| %>
|
154
|
-
# ...
|
155
|
-
# <%= f.buttons :commit, :style => "border:1px;" %>
|
156
|
-
# or
|
157
|
-
# <%= f.buttons :style => "border:1px;" do %>
|
158
|
-
# ...
|
159
|
-
# <% end %>
|
160
|
-
# <% end %>
|
161
|
-
#
|
162
|
-
# @option *args :label [String, Symbol]
|
163
|
-
# Optionally specify text for the legend of the fieldset
|
164
|
-
#
|
165
|
-
# @option *args :name [String, Symbol]
|
166
|
-
# Optionally specify text for the legend of the fieldset (alias for `:label`)
|
167
|
-
#
|
168
|
-
# @todo document i18n keys
|
169
|
-
# @deprecated f.buttons is deprecated in favor of f.actions and will be removed after 2.1
|
170
|
-
def buttons(*args, &block)
|
171
|
-
::ActiveSupport::Deprecation.warn("f.buttons is deprecated in favour of f.actions and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
|
172
|
-
|
173
|
-
html_options = args.extract_options!
|
174
|
-
html_options[:class] ||= "buttons"
|
175
|
-
|
176
|
-
if block_given?
|
177
|
-
field_set_and_list_wrapping(html_options, &block)
|
178
|
-
else
|
179
|
-
args = [:commit] if args.empty?
|
180
|
-
contents = args.map { |button_name| send(:"#{button_name}_button") }
|
181
|
-
field_set_and_list_wrapping(html_options, contents)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# Creates a submit input tag with the value "Save [model name]" (for existing records) or
|
186
|
-
# "Create [model name]" (for new records) by default. The output is an `<input>` tag with the
|
187
|
-
# `type` of `submit` and a class of either `create` or `update` (if Formtastic can determin if)
|
188
|
-
# the record is new or not) with `submit` as a fallback class. The submit button is wrapped in
|
189
|
-
# an `<li>` tag with a class of `commit`, and is intended to be rendered inside a {#buttons}
|
190
|
-
# block which wraps the button in a `fieldset` and `ol`.
|
191
|
-
#
|
192
|
-
# The textual value of the label can be changed from this default through the `:label`
|
193
|
-
# argument or through i18n.
|
194
|
-
#
|
195
|
-
# You can pass HTML attributes down to the `<input>` tag with the `:button_html` option, and
|
196
|
-
# pass HTML attributes to the wrapping `<li>` tag with the `:wrapper_html` option.
|
197
|
-
#
|
198
|
-
# @example Basic usage
|
199
|
-
# # form
|
200
|
-
# <%= semantic_form_for @post do |f| %>
|
201
|
-
# ...
|
202
|
-
# <%= f.buttons do %>
|
203
|
-
# <%= f.commit_button %>
|
204
|
-
# <% end %>
|
205
|
-
# <% end %>
|
206
|
-
#
|
207
|
-
# # output
|
208
|
-
# <form ...>
|
209
|
-
# ...
|
210
|
-
# <fieldset class="buttons">
|
211
|
-
# <ol>
|
212
|
-
# <li class="commit button">
|
213
|
-
# <input name="commit" type="submit" value="Create Post" class="create">
|
214
|
-
# </li>
|
215
|
-
# </ol>
|
216
|
-
# </fieldset>
|
217
|
-
# </form>
|
218
|
-
#
|
219
|
-
# @example Set the value through the `:label` option
|
220
|
-
# <%= f.commit_button :label => "Go" %>
|
221
|
-
#
|
222
|
-
# @example Set the value through the optional first argument (like Rails' `f.submit`)
|
223
|
-
# <%= f.commit_button "Go" %>
|
224
|
-
#
|
225
|
-
# @example Pass HTML attributes down to the `<input>`
|
226
|
-
# <%= f.commit_button :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
|
227
|
-
# <%= f.commit_button :label => "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
|
228
|
-
# <%= f.commit_button "Go", :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
|
229
|
-
#
|
230
|
-
# @example Pass HTML attributes down to the `<li>` wrapper
|
231
|
-
# <%= f.commit_button :wrapper_html => { :class => 'special', :id => 'whatever' } %>
|
232
|
-
# <%= f.commit_button :label => "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>
|
233
|
-
# <%= f.commit_button "Go", :wrapper_html => { :class => 'special', :id => 'whatever' } %>
|
234
|
-
#
|
235
|
-
# @option *args :label [String, Symbol]
|
236
|
-
# Override the label text with a String or a symbold for an i18n translation key
|
237
|
-
#
|
238
|
-
# @option *args :button_html [Hash]
|
239
|
-
# Override or add to the HTML attributes to be passed down to the `<input>` tag
|
240
|
-
#
|
241
|
-
# @option *args :wrapper_html [Hash]
|
242
|
-
# Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
|
243
|
-
#
|
244
|
-
# @todo document i18n keys
|
245
|
-
# @todo strange that `:accesskey` seems to be supported in the top level args as well as `:button_html`
|
246
|
-
# @deprecated f.commit_button is deprecated in favor of f.actions and will be removed after 2.1
|
247
|
-
def commit_button(*args)
|
248
|
-
::ActiveSupport::Deprecation.warn("f.commit_button is deprecated in favour of f.action(:submit) and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
|
249
|
-
|
250
|
-
options = args.extract_options!
|
251
|
-
text = options.delete(:label) || args.shift
|
252
|
-
|
253
|
-
text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
|
254
|
-
Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
|
255
|
-
|
256
|
-
button_html = options.delete(:button_html) || {}
|
257
|
-
button_html[:id] ||= "#{@object_name}_submit"
|
258
|
-
button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))
|
259
|
-
|
260
|
-
wrapper_html = options.delete(:wrapper_html) || {}
|
261
|
-
wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
|
262
|
-
|
263
|
-
accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
|
264
|
-
button_html = button_html.merge(:accesskey => accesskey) if accesskey
|
265
|
-
|
266
|
-
template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
|
267
|
-
end
|
268
|
-
|
269
|
-
def commit_button_object_name
|
270
|
-
if new_or_persisted_object?
|
271
|
-
# Deal with some complications with ActiveRecord::Base.human_name and two name models (eg UserPost)
|
272
|
-
# ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
|
273
|
-
# if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
|
274
|
-
# fall back (human_name == name.humanize) and do our own thing name.underscore.humanize ("User Post")
|
275
|
-
if @object.class.model_name.respond_to?(:human)
|
276
|
-
object_name = @object.class.model_name.human
|
277
|
-
else
|
278
|
-
object_human_name = @object.class.human_name # default is UserPost => "Userpost", but i18n may do better ("User post")
|
279
|
-
crappy_human_name = @object.class.name.humanize # UserPost => "Userpost"
|
280
|
-
decent_human_name = @object.class.name.underscore.humanize # UserPost => "User post"
|
281
|
-
object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
|
282
|
-
end
|
283
|
-
else
|
284
|
-
object_name = @object_name.to_s.send(label_str_method)
|
285
|
-
end
|
286
|
-
|
287
|
-
object_name
|
288
|
-
end
|
289
|
-
|
290
|
-
def commit_button_i18n_key
|
291
|
-
if new_or_persisted_object?
|
292
|
-
key = @object.persisted? ? :update : :create
|
293
|
-
else
|
294
|
-
key = :submit
|
295
|
-
end
|
296
|
-
|
297
|
-
key
|
298
|
-
end
|
299
|
-
|
300
|
-
def commit_button_wrapper_html_class
|
301
|
-
['commit', 'button'] # TODO: Add class reflecting on form action.
|
302
|
-
end
|
303
|
-
|
304
|
-
def new_or_persisted_object?
|
305
|
-
@object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|