phlexi-form 0.4.4 → 0.4.6

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: d6a7276cdcf4ce230a7396395fc8cc45e74379cfe1c06572f5dddff5dc73b82c
4
- data.tar.gz: 40b9ac83c60d2505b2b5e2769bfc5e4006e73bb62aabfe569e6dccdf57434334
3
+ metadata.gz: 2929255d72fb1d3f8c2c810d16b349c94123b21bd0ed4c80254e32ca7051f0e9
4
+ data.tar.gz: 5f9cd0ca0770fb4826dc5d3f38707aac0d29a0a8990634085f3e2c7a68531200
5
5
  SHA512:
6
- metadata.gz: 236052d396b6df4b91abf7dfecc7a4fb983a7ed9d3362cae1488f60ce7d8b92df3921a3bded6d56e7eb7024ae9e9e2df515dcbca4e5addb3da8fa8e875f30b14
7
- data.tar.gz: c5cc9a4cba56e14b7a70d5a5a5ab90ccdb25373ea01662720cdc55205491676136681f3e5a3f2a41593e9e78f3e0f7068bd307768a4c9f256cbd74372cef9107
6
+ metadata.gz: b2824b0ef3da11028f88d8ab0b03e98e73f1e594a1817d32f740194727ff37668d4f7a359af09742c4f2397ee44b765a0c3999952bd941054ff2ab268f4bb28e
7
+ data.tar.gz: d7dafb70c5bea0fde0f922fc02d4cc8583763e1bfe334538a4b971a416a0154dbbf8c4718692d88b2731a2870f58c191ceb71f2fc10bb017214239411543ffb3
@@ -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 ||= (object_form_method || "get").to_s.downcase
187
- ActiveSupport::StringInquirer.new(@form_method)
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
- !form_method.get? && ((defined?(helpers) && helpers) || options[:authenticity_token])
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
- form_method.get? || form_method.post?
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 : "post"
247
+ standard_form_method? ? form_method : :post
244
248
  end
245
249
 
246
250
  # Generates the form attributes hash.
@@ -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, :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
- attributes = mix(input_attributes, attributes) if component_class.include?(Phlexi::Form::Components::Concerns::HandlesInput)
256
- component = component_class.new(self, **apply_component_theme(attributes, theme_key), &)
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 attributes if attributes.key?(:class!)
273
+ return {} if attributes.key?(:class!)
268
274
 
269
275
  theme_key = attributes.delete(:theme) || theme_key
270
- mix({class: themed(theme_key, self)}, attributes)
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 nil unless association_reflection.present?
286
+ return unless association_reflection.present?
285
287
 
286
288
  value = object.public_send(key)
287
289
  case association_reflection.macro
@@ -20,6 +20,8 @@ module Phlexi
20
20
  association_reflection.polymorphic? ? :"polymorphic_#{association_reflection.macro}" : association_reflection.macro
21
21
  when :attachment, :binary
22
22
  :file
23
+ when :citext
24
+ infer_string_field_type || :string
23
25
  when :date, :time, :datetime, :boolean, :hstore
24
26
  inferred_field_type
25
27
  else
@@ -17,7 +17,7 @@ module Phlexi
17
17
  end
18
18
  else
19
19
  input = each_with_object({}) do |child, hash|
20
- hash.merge! child.extract_input(params[key])
20
+ hash.merge! child.extract_input(params[key]) if params
21
21
  end
22
22
  {key => input}
23
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlexi
4
4
  module Form
5
- VERSION = "0.4.4"
5
+ VERSION = "0.4.6"
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.4.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-06 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex