phlexi-form 0.5.11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a90eefb63575ca59ebab859b3d025e4894b694553f0875848238f25c6d39d01e
4
- data.tar.gz: 3f972bace2dd06428f6ec851828ceb61230332e34506c0852281182709581532
3
+ metadata.gz: 2112fb7333817aef3f7d477f109c96258e03bd3d5a56900021c424c17976de85
4
+ data.tar.gz: 96facfa8646307cd82cbcd69c4679ef4a31dd59be3a0df33926490830667a538
5
5
  SHA512:
6
- metadata.gz: 82ebaa7e33876dea848848a2fbf1ab1d024c24a3e074a34fd11d2ad18abb650ca09aae721bebb56c7993709b193d9b8ddf740613bff5274ebec9583715fb0d62
7
- data.tar.gz: 48e3363a023875c61790f5173edf95e898b778709e01c4d3d156b95afc8e5a60960fd1d1f7ef4d05ce1b55ce49b99fdef71584f619c71ec21c63fe485f9d523e
6
+ metadata.gz: 48f8143f6cf980a6ae60a9b269e5dafa17bfe6712178de1f42be026a80a69419e76fd1d082946fadde620a0b80d64a7bcb6fadb4f7aeffbcef0e439ac8d9f141
7
+ data.tar.gz: 5df2b6fa53da946d5c901cccade7002db1e2769edae64f75187c47ab923b91ac41dce168275f33b7926cb040c850d82412681f015166bf0ee6c3c561c5b2839a
@@ -161,15 +161,8 @@ module Phlexi
161
161
  create_component(Components::Select, :select, **, &)
162
162
  end
163
163
 
164
- def belongs_to_tag(**options, &)
165
- options.fetch(:input_param) {
166
- options[:input_param] = if association_reflection.respond_to?(:options) && association_reflection.options[:foreign_key]
167
- association_reflection.options[:foreign_key]
168
- else
169
- :"#{association_reflection.name}_id"
170
- end
171
- }
172
- select_tag(**options, &)
164
+ def belongs_to_tag(**, &)
165
+ create_component(Components::BelongsTo, :has_many, **, &)
173
166
  end
174
167
 
175
168
  def polymorphic_belongs_to_tag(**, &)
@@ -182,12 +175,8 @@ module Phlexi
182
175
  raise NotImplementedError, "has_one associations are NOT supported"
183
176
  end
184
177
 
185
- def has_many_tag(**options, &)
186
- options.fetch(:input_param) {
187
- options[:input_param] = :"#{association_reflection.name.to_s.singularize}_ids"
188
- }
189
-
190
- select_tag(**options, &)
178
+ def has_many_tag(**, &)
179
+ create_component(Components::HasMany, :has_many, **, &)
191
180
  end
192
181
  alias_method :has_and_belongs_to_many_tag, :has_many_tag
193
182
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlexi
4
+ module Form
5
+ module Components
6
+ class BelongsTo < Select
7
+ protected
8
+
9
+ delegate :association_reflection, to: :field
10
+
11
+ def build_attributes
12
+ super
13
+
14
+ build_belongs_to_attributes
15
+ end
16
+
17
+ def build_belongs_to_attributes
18
+ attributes.fetch(:input_param) do
19
+ attributes[:input_param] = if association_reflection.respond_to?(:options) && association_reflection.options[:foreign_key]
20
+ association_reflection.options[:foreign_key]
21
+ else
22
+ :"#{association_reflection.name}_id"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlexi
4
+ module Form
5
+ module Components
6
+ class HasMany < Select
7
+ protected
8
+
9
+ delegate :association_reflection, to: :field
10
+
11
+ def build_attributes
12
+ super
13
+
14
+ build_has_many_attributes
15
+ end
16
+
17
+ def build_has_many_attributes
18
+ attributes.fetch(:input_param) {
19
+ attributes[:input_param] = :"#{association_reflection.name.to_s.singularize}_ids"
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -130,7 +130,19 @@ module Phlexi
130
130
  file: :input,
131
131
  valid_file: :valid_input,
132
132
  invalid_file: :invalid_input,
133
- neutral_file: :neutral_input
133
+ neutral_file: :neutral_input,
134
+
135
+ # BelongsTo
136
+ belongs_to: :select,
137
+ valid_belongs_to: :valid_select,
138
+ invalid_belongs_to: :invalid_select,
139
+ neutral_belongs_to: :neutral_select,
140
+
141
+ # HasMany
142
+ has_many: :select,
143
+ valid_has_many: :valid_select,
144
+ invalid_has_many: :invalid_select,
145
+ neutral_has_many: :neutral_select
134
146
 
135
147
  }.freeze
136
148
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlexi
4
4
  module Form
5
- VERSION = "0.5.11"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexi-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-30 00:00:00.000000000 Z
11
+ date: 2024-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -207,6 +207,7 @@ files:
207
207
  - lib/phlexi/form/builder.rb
208
208
  - lib/phlexi/form/choices_mapper.rb
209
209
  - lib/phlexi/form/components/base.rb
210
+ - lib/phlexi/form/components/belongs_to.rb
210
211
  - lib/phlexi/form/components/checkbox.rb
211
212
  - lib/phlexi/form/components/collection_checkboxes.rb
212
213
  - lib/phlexi/form/components/collection_radio_buttons.rb
@@ -220,6 +221,7 @@ files:
220
221
  - lib/phlexi/form/components/file_input.rb
221
222
  - lib/phlexi/form/components/form_errors.rb
222
223
  - lib/phlexi/form/components/full_error.rb
224
+ - lib/phlexi/form/components/has_many.rb
223
225
  - lib/phlexi/form/components/hint.rb
224
226
  - lib/phlexi/form/components/input.rb
225
227
  - lib/phlexi/form/components/input_array.rb