forme 1.1.0 → 1.2.0
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 +4 -4
- data/CHANGELOG +12 -0
- data/README.rdoc +12 -2
- data/lib/forme.rb +20 -13
- data/lib/forme/version.rb +1 -1
- data/lib/sequel/plugins/forme.rb +12 -3
- data/spec/forme_spec.rb +22 -14
- data/spec/sequel_helper.rb +7 -0
- data/spec/sequel_plugin_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74dc2b36401ea1374b6e0790ee2292b793beac2
|
4
|
+
data.tar.gz: 33e3d4e182a2af0513ac37e3200c0eda9826d08b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c9e809e2c1cd4ea343de693f4611c5f42e5f320723545ec7f76d2e1112d3d695159ed791c2ff0f7810ed2e1bdfe01eb1d850fcd37493c13ebe3e98aa413b0a5
|
7
|
+
data.tar.gz: b1dfd6ce07b3e35e0873e86f6956662779ecd46f545e0c030a5e557da6cf19df7a8f9dda20ef9feb2a4f418e7d231d33fff6e4f4bcf35e858816c2e9f53fcbd1
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 1.2.0 (2014-11-06)
|
2
|
+
|
3
|
+
* Support pg_array_to_many associations in the Sequel plugin, treating them similarly to other *_to_many associations (jeremyevans)
|
4
|
+
|
5
|
+
* When using :grid option to subform in the Sequel plugin, :inputs_opts can be used to pass options to the InputsWrapper (jeremyevans)
|
6
|
+
|
7
|
+
* Support :error_attr option for inputs, for setting attributes to use for error message span (jeremyevans)
|
8
|
+
|
9
|
+
* Make explicit labeler use label-before and label-after classes specifying the label position (jeremyevans)
|
10
|
+
|
11
|
+
* Support :size option for select inputs (jeremyevans)
|
12
|
+
|
1
13
|
=== 1.1.0 (2014-09-07)
|
2
14
|
|
3
15
|
* Make form without a block in the ERB integration still use hidden tags if method is post (jeremyevans)
|
data/README.rdoc
CHANGED
@@ -424,11 +424,14 @@ This will create a form similar to:
|
|
424
424
|
For one_to_many and many_to_many associations, you will probably want to use the
|
425
425
|
+association_pks+ plugin that ships with Sequel.
|
426
426
|
|
427
|
+
This supports the pg_array_to_many association type that comes with Sequel's
|
428
|
+
+pg_array_association+ plugin.
|
429
|
+
|
427
430
|
association input options:
|
428
431
|
|
429
432
|
:as :: For many_to_one associations, set to :radio to use a series of radio buttons instead
|
430
|
-
a select input. For one_to_many and
|
431
|
-
use a series of checkboxes instead of a multiple select input.
|
433
|
+
a select input. For one_to_many, many_to_many, and pg_array_to_many associations, set
|
434
|
+
to :checkbox to use a series of checkboxes instead of a multiple select input.
|
432
435
|
:dataset :: If a Dataset, uses the dataset to retrieve the options. If a Proc or Method,
|
433
436
|
calls the proc or method with the default dataset, and should return a modified
|
434
437
|
dataset to use.
|
@@ -502,6 +505,8 @@ subform options:
|
|
502
505
|
be created via the :inputs option. If you are not providing
|
503
506
|
an :inputs option or are using a block with additional inputs,
|
504
507
|
you should specify this option.
|
508
|
+
:inputs_opts :: When using the :grid option, this allows you to specify options
|
509
|
+
to pass to the table InputsWrapper.
|
505
510
|
|
506
511
|
= ERB Support
|
507
512
|
|
@@ -611,6 +616,7 @@ Creates a select tag, containing option tags specified by the :options option.
|
|
611
616
|
:selected :: The value that should be selected. Any options that are equal to
|
612
617
|
this value (or included in this value if a multiple select box),
|
613
618
|
are set to selected.
|
619
|
+
:size :: Uses the size attribute on the tag
|
614
620
|
:text_method :: If set, each entry in the array has this option called on
|
615
621
|
it to get the text of the object.
|
616
622
|
:value :: Same as :selected, but has lower priority.
|
@@ -737,6 +743,10 @@ Forme ships with a bunch of built-in transformers that you can use:
|
|
737
743
|
|
738
744
|
:default :: modifies tag to add an error class and adds a span with the error message
|
739
745
|
|
746
|
+
This supports the following options:
|
747
|
+
|
748
|
+
:error_attr :: A hash of attributes to use for the span with the error message
|
749
|
+
|
740
750
|
=== +labeler+
|
741
751
|
|
742
752
|
:default :: uses implicit labels, where the tag is a child of the label tag
|
data/lib/forme.rb
CHANGED
@@ -792,9 +792,10 @@ module Forme
|
|
792
792
|
# Takes a select input and turns it into a select tag with (possibly) option
|
793
793
|
# children tags.
|
794
794
|
def format_select
|
795
|
-
|
796
|
-
|
795
|
+
@attr[:multiple] = :multiple if @opts[:multiple]
|
796
|
+
copy_options_to_attributes([:size])
|
797
797
|
|
798
|
+
if os = process_select_options(@opts[:options])
|
798
799
|
os = os.map do |label, value, sel, attrs|
|
799
800
|
if value || sel
|
800
801
|
attrs = attrs.dup
|
@@ -1104,7 +1105,10 @@ module Forme
|
|
1104
1105
|
|
1105
1106
|
# Return tag with error message span tag after it.
|
1106
1107
|
def call(tag, input)
|
1107
|
-
|
1108
|
+
attr = input.opts[:error_attr]
|
1109
|
+
attr = attr ? attr.dup : {}
|
1110
|
+
Forme.attr_classes(attr, 'error_message')
|
1111
|
+
[tag, input.tag(:span, attr, input.opts[:error])]
|
1108
1112
|
end
|
1109
1113
|
end
|
1110
1114
|
|
@@ -1166,19 +1170,22 @@ module Forme
|
|
1166
1170
|
end
|
1167
1171
|
end
|
1168
1172
|
end
|
1169
|
-
if [:radio, :checkbox].include?(input.type)
|
1170
|
-
t = [tag, input.tag(:label, {:for=>input.opts.fetch(:label_for, id)}.merge(input.opts[:label_attr]||{}), [input.opts[:label]])]
|
1171
|
-
pos = :before
|
1172
|
-
else
|
1173
|
-
t = [input.tag(:label, {:for=>input.opts.fetch(:label_for, id)}.merge(input.opts[:label_attr]||{}), [input.opts[:label]]), tag]
|
1174
|
-
pos = :after
|
1175
|
-
end
|
1176
1173
|
|
1177
|
-
|
1178
|
-
|
1174
|
+
label_attr = input.opts[:label_attr]
|
1175
|
+
label_attr = label_attr ? label_attr.dup : {}
|
1176
|
+
label_attr[:for] ||= input.opts.fetch(:label_for, id)
|
1177
|
+
lpos = input.opts[:label_position] || ([:radio, :checkbox].include?(input.type) ? :after : :before)
|
1178
|
+
|
1179
|
+
Forme.attr_classes(label_attr, "label-#{lpos}")
|
1180
|
+
label = input.tag(:label, label_attr, [input.opts[:label]])
|
1181
|
+
|
1182
|
+
t = if lpos == :before
|
1183
|
+
[label, tag]
|
1179
1184
|
else
|
1180
|
-
|
1185
|
+
[tag, label]
|
1181
1186
|
end
|
1187
|
+
|
1188
|
+
t
|
1182
1189
|
end
|
1183
1190
|
end
|
1184
1191
|
|
data/lib/forme/version.rb
CHANGED
data/lib/sequel/plugins/forme.rb
CHANGED
@@ -87,7 +87,8 @@ module Sequel # :nodoc:
|
|
87
87
|
if grid
|
88
88
|
labels = opts.fetch(:labels){opts[:inputs].map{|l, *| humanize(l)} if opts[:inputs]}
|
89
89
|
legend = opts.fetch(:legend){humanize(association)}
|
90
|
-
|
90
|
+
inputs_opts = opts[:inputs_opts] || {}
|
91
|
+
inputs(inputs_opts.merge(:inputs_wrapper=>:table, :nested_inputs_wrapper=>:tr, :wrapper=>:td, :labeler=>nil, :labels=>labels, :legend=>legend), &contents)
|
91
92
|
else
|
92
93
|
contents.call
|
93
94
|
end
|
@@ -285,14 +286,21 @@ module Sequel # :nodoc:
|
|
285
286
|
key = ref[:key]
|
286
287
|
klass = ref.associated_class
|
287
288
|
pk = klass.primary_key
|
288
|
-
|
289
|
+
label = klass.send(:singularize, ref[:name])
|
290
|
+
|
291
|
+
field = if ref[:type] == :pg_array_to_many
|
292
|
+
ref[:key]
|
293
|
+
else
|
294
|
+
"#{label}_pks"
|
295
|
+
end
|
296
|
+
|
289
297
|
unless opts.has_key?(:key)
|
290
298
|
opts[:array] = true unless opts.has_key?(:array)
|
291
299
|
opts[:key] = field
|
292
300
|
end
|
293
301
|
opts[:value] = obj.send(ref[:name]).map{|x| x.send(pk)} unless opts.has_key?(:value)
|
294
302
|
opts[:options] = association_select_options(ref) unless opts.has_key?(:options)
|
295
|
-
handle_label(
|
303
|
+
handle_label(label)
|
296
304
|
if opts.delete(:as) == :checkbox
|
297
305
|
_input(:checkboxset, opts)
|
298
306
|
else
|
@@ -301,6 +309,7 @@ module Sequel # :nodoc:
|
|
301
309
|
end
|
302
310
|
end
|
303
311
|
alias association_many_to_many association_one_to_many
|
312
|
+
alias association_pg_array_to_many association_one_to_many
|
304
313
|
|
305
314
|
# Return an array of two element arrays representing the
|
306
315
|
# select options that should be created.
|
data/spec/forme_spec.rb
CHANGED
@@ -239,6 +239,10 @@ describe "Forme plain forms" do
|
|
239
239
|
@f.input(:select).to_s.should == '<select></select>'
|
240
240
|
end
|
241
241
|
|
242
|
+
specify "should respect multiple and size options in select tag" do
|
243
|
+
@f.input(:select, :multiple=>true, :size=>10).to_s.should == '<select multiple="multiple" size="10"></select>'
|
244
|
+
end
|
245
|
+
|
242
246
|
specify "should create date tag" do
|
243
247
|
@f.input(:date).to_s.should == '<input type="date"/>'
|
244
248
|
end
|
@@ -252,7 +256,7 @@ describe "Forme plain forms" do
|
|
252
256
|
end
|
253
257
|
|
254
258
|
specify "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
|
255
|
-
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.should == %{<tr><td><label for="bar_year">Baz</label></td><td><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
|
259
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.should == %{<tr><td><label class="label-before" for="bar_year">Baz</label></td><td><select id="bar_year" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
|
256
260
|
end
|
257
261
|
|
258
262
|
specify "should use multiple select boxes for datetimes if the :as=>:select option is given" do
|
@@ -439,6 +443,10 @@ describe "Forme plain forms" do
|
|
439
443
|
@f.input(:text, :error=>'Bad Stuff!', :class=>'bar', :value=>'foo').to_s.should == '<input class="bar error" type="text" value="foo"/><span class="error_message">Bad Stuff!</span>'
|
440
444
|
end
|
441
445
|
|
446
|
+
specify "should respect :error_attr option for setting the attributes for the error message span" do
|
447
|
+
@f.input(:text, :error=>'Bad Stuff!', :value=>'foo', :error_attr=>{:class=>'foo'}).to_s.should == '<input class="error" type="text" value="foo"/><span class="foo error_message">Bad Stuff!</span>'
|
448
|
+
end
|
449
|
+
|
442
450
|
specify "#open should return an opening tag" do
|
443
451
|
@f.open(:action=>'foo', :method=>'post').to_s.should == '<form action="foo" method="post">'
|
444
452
|
end
|
@@ -559,19 +567,19 @@ describe "Forme plain forms" do
|
|
559
567
|
end
|
560
568
|
|
561
569
|
specify "inputs should accept a :labeler option to use a custom labeler" do
|
562
|
-
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.should == '<label for="foo">bar</label><textarea id="foo"></textarea>'
|
570
|
+
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo).to_s.should == '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
|
563
571
|
end
|
564
572
|
|
565
573
|
specify "inputs handle explicit labels with :label_position=>:after" do
|
566
|
-
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.should == '<textarea id="foo"></textarea><label for="foo">bar</label>'
|
574
|
+
@f.input(:textarea, :labeler=>:explicit, :label=>'bar', :id=>:foo, :label_position=>:after).to_s.should == '<textarea id="foo"></textarea><label class="label-after" for="foo">bar</label>'
|
567
575
|
end
|
568
576
|
|
569
577
|
specify "should handle explicit labels with checkboxes" do
|
570
|
-
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.should == '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label for="bar">Foo</label>'
|
578
|
+
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar').to_s.should == '<input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/><label class="label-after" for="bar">Foo</label>'
|
571
579
|
end
|
572
580
|
|
573
581
|
specify "should handle explicit labels with checkboxes with :label_position=>:before" do
|
574
|
-
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.should == '<label for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
|
582
|
+
@f.input(:checkbox, :labeler=>:explicit, :label=>'Foo', :value=>'foo', :name=>'a', :id=>'bar', :label_position=>:before).to_s.should == '<label class="label-before" for="bar">Foo</label><input id="bar_hidden" name="a" type="hidden" value="0"/><input id="bar" name="a" type="checkbox" value="foo"/>'
|
575
583
|
end
|
576
584
|
|
577
585
|
specify "inputs handle implicit labels or checkboxes without hidden fields with :label_position=>:before" do
|
@@ -706,15 +714,15 @@ describe "Forme built-in custom" do
|
|
706
714
|
end
|
707
715
|
|
708
716
|
specify "labeler: explicit uses an explicit label with for attribute" do
|
709
|
-
Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.should == '<label for="foo">bar</label><textarea id="foo"></textarea>'
|
717
|
+
Forme::Form.new(:labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="foo">bar</label><textarea id="foo"></textarea>'
|
710
718
|
end
|
711
719
|
|
712
720
|
specify "labeler: explicit handles the key option correctly" do
|
713
|
-
Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.should == '<label for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
|
721
|
+
Forme::Form.new(:labeler=>:explicit, :namespace=>:baz).input(:textarea, :key=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="baz_foo">bar</label><textarea id="baz_foo" name="baz[foo]"></textarea>'
|
714
722
|
end
|
715
723
|
|
716
724
|
specify "labeler: explicit should handle tags with errors" do
|
717
|
-
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.should == '<label for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
|
725
|
+
Forme::Form.new(:labeler=>:explicit).input(:text, :error=>'Bad Stuff!', :value=>'f', :id=>'foo', :label=>'bar').to_s.should == '<label class="label-before" for="foo">bar</label><input class="error" id="foo" type="text" value="f"/><span class="error_message">Bad Stuff!</span>'
|
718
726
|
end
|
719
727
|
|
720
728
|
specify "wrapper: li wraps tag in an li" do
|
@@ -748,15 +756,15 @@ describe "Forme built-in custom" do
|
|
748
756
|
end
|
749
757
|
|
750
758
|
specify "wrapper: trtd supports multiple tags in separate tds" do
|
751
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.should == '<tr><td><label for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
|
759
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo').to_s.should == '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea id="foo"></textarea></td></tr>'
|
752
760
|
end
|
753
761
|
|
754
762
|
specify "wrapper: trtd should use at most 2 td tags" do
|
755
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.should == '<tr><td><label for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
|
763
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:textarea, :id=>'foo', :label=>'Foo', :error=>'Bar').to_s.should == '<tr><td><label class="label-before" for="foo">Foo</label></td><td><textarea class="error" id="foo"></textarea><span class="error_message">Bar</span></td></tr>'
|
756
764
|
end
|
757
765
|
|
758
766
|
specify "wrapper: trtd should handle inputs with label after" do
|
759
|
-
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.should == '<tr><td><label for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
|
767
|
+
Forme::Form.new(:wrapper=>:trtd, :labeler=>:explicit).input(:checkbox, :id=>'foo', :name=>'foo', :label=>'Foo').to_s.should == '<tr><td><label class="label-after" for="foo">Foo</label></td><td><input id="foo_hidden" name="foo" type="hidden" value="0"/><input id="foo" name="foo" type="checkbox"/></td></tr>'
|
760
768
|
end
|
761
769
|
|
762
770
|
specify "wrapper: tr should use a td wrapper and tr inputs_wrapper" do
|
@@ -884,17 +892,17 @@ describe "Forme configurations" do
|
|
884
892
|
end
|
885
893
|
|
886
894
|
specify "config: :formastic uses fieldset_ol inputs_wrapper and li wrapper, and explicit labeler" do
|
887
|
-
Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
895
|
+
Forme::Form.new(:config=>:formtastic).inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
888
896
|
end
|
889
897
|
|
890
898
|
specify "should be able to set a default configuration with Forme.default_config=" do
|
891
899
|
Forme.default_config = :formtastic
|
892
|
-
Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
900
|
+
Forme::Form.new.inputs([[:textarea, {:id=>:foo, :label=>'Foo'}]]).to_s.should == '<fieldset class="inputs"><ol><li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li></ol></fieldset>'
|
893
901
|
end
|
894
902
|
|
895
903
|
specify "should have #register_config register a configuration for later use" do
|
896
904
|
Forme.register_config(:foo, :wrapper=>:li, :labeler=>:explicit)
|
897
|
-
Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.should == '<li><label for="foo">Foo</label><textarea id="foo"></textarea></li>'
|
905
|
+
Forme::Form.new(:config=>:foo).input(:textarea, :id=>:foo, :label=>'Foo').to_s.should == '<li><label class="label-before" for="foo">Foo</label><textarea id="foo"></textarea></li>'
|
898
906
|
end
|
899
907
|
|
900
908
|
specify "should have #register_config support a :base option to base it on an existing config" do
|
data/spec/sequel_helper.rb
CHANGED
@@ -55,6 +55,13 @@ class Album < Sequel::Model
|
|
55
55
|
one_to_many :tracks
|
56
56
|
many_to_many :tags
|
57
57
|
|
58
|
+
plugin :pg_array_associations
|
59
|
+
pg_array_to_many :atags, :class=>:Tag
|
60
|
+
|
61
|
+
def atag_ids
|
62
|
+
@atag_ids ||= [1,2]
|
63
|
+
end
|
64
|
+
|
58
65
|
def artist_name
|
59
66
|
artist.name if artist
|
60
67
|
end
|
data/spec/sequel_plugin_spec.rb
CHANGED
@@ -234,6 +234,12 @@ describe "Forme Sequel::Model forms" do
|
|
234
234
|
@c.input(:tags).to_s.should == '<label>Tags: <select id="album_tag_pks" multiple="multiple" name="album[tag_pks][]"><option value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></label>'
|
235
235
|
end
|
236
236
|
|
237
|
+
specify "should use a multiple select box for pg_array_to_many associations" do
|
238
|
+
@b.input(:atags).to_s.should == '<label>Atags: <select id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></label>'
|
239
|
+
@c.obj.atag_ids.delete(1)
|
240
|
+
@c.input(:atags).to_s.should == '<label>Atags: <select id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></label>'
|
241
|
+
end
|
242
|
+
|
237
243
|
specify "should use a regular select box for *_to_many associations if multiple if false" do
|
238
244
|
@b.input(:tracks, :multiple=>false).to_s.should == '<label>Tracks: <select id="album_track_pks" name="album[track_pks][]"><option value="1">m</option><option value="2">n</option><option value="3">o</option></select></label>'
|
239
245
|
@c.input(:tags, :multiple=>false).to_s.should == '<label>Tags: <select id="album_tag_pks" name="album[tag_pks][]"><option value="1">s</option><option value="2">t</option><option value="3">u</option></select></label>'
|
@@ -389,6 +395,10 @@ describe "Forme Sequel::Model forms" do
|
|
389
395
|
Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.should == '<form class="forme album" method="post"><table><caption>Artist</caption><tr><th>Name</th></tr><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></table></form>'
|
390
396
|
end
|
391
397
|
|
398
|
+
specify "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
|
399
|
+
Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.should == '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><tr><th>Name</th></tr><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></table></form>'
|
400
|
+
end
|
401
|
+
|
392
402
|
specify "should have #subform :grid option handle :legend and :labels options" do
|
393
403
|
Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.should == '<form class="forme album" method="post"><table><caption>Foo</caption><tr><th>Bar</th></tr><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></table></form>'
|
394
404
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Forme is a forms library with the following goals:
|