phlexi-form 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phlexi/form/base.rb +10 -6
- data/lib/phlexi/form/builder.rb +13 -11
- data/lib/phlexi/form/structure/namespace.rb +1 -1
- data/lib/phlexi/form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2929255d72fb1d3f8c2c810d16b349c94123b21bd0ed4c80254e32ca7051f0e9
|
4
|
+
data.tar.gz: 5f9cd0ca0770fb4826dc5d3f38707aac0d29a0a8990634085f3e2c7a68531200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2824b0ef3da11028f88d8ab0b03e98e73f1e594a1817d32f740194727ff37668d4f7a359af09742c4f2397ee44b765a0c3999952bd941054ff2ab268f4bb28e
|
7
|
+
data.tar.gz: d7dafb70c5bea0fde0f922fc02d4cc8583763e1bfe334538a4b971a416a0154dbbf8c4718692d88b2731a2870f58c191ceb71f2fc10bb017214239411543ffb3
|
data/lib/phlexi/form/base.rb
CHANGED
@@ -49,6 +49,7 @@ module Phlexi
|
|
49
49
|
def initialize(record, action: nil, method: nil, attributes: {}, **options)
|
50
50
|
@form_action = action
|
51
51
|
@form_method = method
|
52
|
+
@dom_id = attributes.delete(:id)
|
52
53
|
@attributes = attributes
|
53
54
|
@namespace_klass = options.delete(:namespace_klass) || default_namespace_klass
|
54
55
|
@builder_klass = options.delete(:builder_klass) || default_builder_klass
|
@@ -135,7 +136,7 @@ module Phlexi
|
|
135
136
|
#
|
136
137
|
# @return [void]
|
137
138
|
def initialize_namespace
|
138
|
-
@namespace = namespace_klass.root(key, object: object, builder_klass: builder_klass)
|
139
|
+
@namespace = namespace_klass.root(key, object: object, builder_klass: builder_klass, dom_id: @dom_id)
|
139
140
|
end
|
140
141
|
|
141
142
|
# Initializes form attributes.
|
@@ -183,15 +184,18 @@ module Phlexi
|
|
183
184
|
#
|
184
185
|
# @return [ActiveSupport::StringInquirer] The form's HTTP method
|
185
186
|
def form_method
|
186
|
-
@form_method ||=
|
187
|
-
|
187
|
+
@form_method ||= object_form_method || :get
|
188
|
+
end
|
189
|
+
|
190
|
+
def inquirable_form_method
|
191
|
+
ActiveSupport::StringInquirer.new(form_method.to_s.downcase)
|
188
192
|
end
|
189
193
|
|
190
194
|
# Checks if the authenticity token should be included.
|
191
195
|
#
|
192
196
|
# @return [Boolean] True if the authenticity token should be included, false otherwise
|
193
197
|
def has_authenticity_token?
|
194
|
-
!
|
198
|
+
!inquirable_form_method.get? && ((defined?(helpers) && helpers) || options[:authenticity_token])
|
195
199
|
end
|
196
200
|
|
197
201
|
# Retrieves the authenticity token.
|
@@ -233,14 +237,14 @@ module Phlexi
|
|
233
237
|
#
|
234
238
|
# @return [Boolean] True if the form method is standard, false otherwise
|
235
239
|
def standard_form_method?
|
236
|
-
|
240
|
+
inquirable_form_method.get? || inquirable_form_method.post?
|
237
241
|
end
|
238
242
|
|
239
243
|
# Returns the standardized form method for the HTML form tag.
|
240
244
|
#
|
241
245
|
# @return [String] The standardized form method
|
242
246
|
def standardized_form_method
|
243
|
-
standard_form_method? ? form_method :
|
247
|
+
standard_form_method? ? form_method : :post
|
244
248
|
end
|
245
249
|
|
246
250
|
# Generates the form attributes hash.
|
data/lib/phlexi/form/builder.rb
CHANGED
@@ -43,8 +43,8 @@ module Phlexi
|
|
43
43
|
#
|
44
44
|
# @param attributes [Hash] Additional attributes for the input.
|
45
45
|
# @return [Components::Input] The input component.
|
46
|
-
def input_tag(**, &)
|
47
|
-
create_component(Components::Input,
|
46
|
+
def input_tag(theme: :input, **, &)
|
47
|
+
create_component(Components::Input, theme, **, &)
|
48
48
|
end
|
49
49
|
|
50
50
|
def string_tag(**, &)
|
@@ -252,8 +252,14 @@ module Phlexi
|
|
252
252
|
protected
|
253
253
|
|
254
254
|
def create_component(component_class, theme_key, **attributes, &)
|
255
|
-
|
256
|
-
|
255
|
+
theme_attributes = apply_component_theme(attributes, theme_key)
|
256
|
+
extra_attributes = if component_class.include?(Phlexi::Form::Components::Concerns::HandlesInput)
|
257
|
+
input_attributes
|
258
|
+
else
|
259
|
+
{}
|
260
|
+
end
|
261
|
+
attributes = mix(theme_attributes, extra_attributes, attributes)
|
262
|
+
component = component_class.new(self, **attributes, &)
|
257
263
|
if component_class.include?(Components::Concerns::ExtractsInput)
|
258
264
|
raise "input component already defined: #{@field_input_extractor.inspect}" if @field_input_extractor
|
259
265
|
|
@@ -264,10 +270,10 @@ module Phlexi
|
|
264
270
|
end
|
265
271
|
|
266
272
|
def apply_component_theme(attributes, theme_key)
|
267
|
-
return
|
273
|
+
return {} if attributes.key?(:class!)
|
268
274
|
|
269
275
|
theme_key = attributes.delete(:theme) || theme_key
|
270
|
-
|
276
|
+
{class: themed(theme_key, self)}
|
271
277
|
end
|
272
278
|
|
273
279
|
def determine_initial_value(value)
|
@@ -276,12 +282,8 @@ module Phlexi
|
|
276
282
|
determine_value_from_association || super
|
277
283
|
end
|
278
284
|
|
279
|
-
def determine_value_from_object
|
280
|
-
object.respond_to?(key) ? object.public_send(key) : nil
|
281
|
-
end
|
282
|
-
|
283
285
|
def determine_value_from_association
|
284
|
-
return
|
286
|
+
return unless association_reflection.present?
|
285
287
|
|
286
288
|
value = object.public_send(key)
|
287
289
|
case association_reflection.macro
|
data/lib/phlexi/form/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.6
|
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-10-
|
11
|
+
date: 2024-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|