phlex-forms 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dc70d0937facff7734915cad7ed5d94e6f41ec60e8131c20ac35064fcc6b321
4
- data.tar.gz: d409e64d0fab4e109e8d5afc3de2fa00f6b71338e50c9a788b734f19dc3828d8
3
+ metadata.gz: c814b751d3d8dd050595b4d29aa7a261dd0b5dbb15787912a58e676fe09d76a9
4
+ data.tar.gz: 1c9bb1ff0df9584b34a7e9e67a4698a04569d985b0406f9e9d79e60d2abe160f
5
5
  SHA512:
6
- metadata.gz: 1bbc82f882907bb30c7358d8cb2891d7d2684e82bb4c5f82af76b97e5a2dd6e37206d5dbddc69a07b7c18b8335f4313681dcc379e59019a365487729207896bc
7
- data.tar.gz: 4d9193486eb8ce1fbd1777262d5cfa00cb124ce0fdc4c378efb01bfe05d6f03c1c45835ec92b5d523b3a28956d04518ccc7868864558b229c166959bc20ac594
6
+ metadata.gz: 6d86f0ca8fa5497a118b5e137e9bd23b67a68b4db6076cad19a38d6dc4bad4e3d42a5b3958077666e5f1370658b6069dc9787d816c3904c4717c5f5725d7cac0
7
+ data.tar.gz: fbe09ab98824da11331b9a6d4abaf502356bb617157b12a68a82096eab790b2d5e794bd2457e8ccd94651e418b69dbab76317e3bfb6542f7dfe7d60d37479d25
@@ -8,6 +8,7 @@ module Forms
8
8
  include PhlexForms::Builder
9
9
 
10
10
  attr_reader :model, :scope, :errors, :parent_form
11
+ alias object model # Rails form-builder compatibility (mirrors Forms::Form)
11
12
 
12
13
  def initialize(model:, scope:, errors:, parent_form:)
13
14
  @model = model
@@ -24,6 +25,7 @@ module Forms
24
25
  def field_object(name, error_name: nil)
25
26
  Forms::Field.new(name:, model: @model, scope: @scope, errors: @errors, form: @parent_form, error_name:)
26
27
  end
28
+ alias [] field_object # `item_form[:id].hidden` — Rails form-builder-style access
27
29
 
28
30
  def default_field_variants
29
31
  @parent_form.default_field_variants
data/lib/forms/form.rb CHANGED
@@ -19,6 +19,12 @@ module Forms
19
19
 
20
20
  attr_reader :model, :scope, :url, :method, :errors, :validate, :theme
21
21
 
22
+ # Rails form-builder compatibility: `f.object` / `f.object_name` mirror the
23
+ # ActionView FormBuilder API so call sites that introspect the bound record
24
+ # (`f.object.class.reflect_on_association(...)`) keep working.
25
+ alias object model
26
+ alias object_name scope
27
+
22
28
  def initialize(*modifiers, model: nil, scope: nil, url: nil, method: nil, validate: false,
23
29
  field_variants: nil, theme: nil, live: nil, **options)
24
30
  if live
@@ -66,6 +72,7 @@ module Forms
66
72
  def field_object(name, error_name: nil)
67
73
  Forms::Field.new(name:, model: @model, scope: @scope, errors: @errors, form: self, error_name:)
68
74
  end
75
+ alias [] field_object # `f[:email].hidden` — Rails form-builder-style access
69
76
 
70
77
  def submit(*, **, &)
71
78
  render theme[:submit].new(*, model: @model, **, &)
@@ -32,9 +32,16 @@ module Forms
32
32
  end
33
33
 
34
34
  def view_template
35
+ # Build the options on `self` — the TimeZoneOptionsForSelect helper is
36
+ # included here, NOT on the yielded DaisyUI::Select (`el`), so calling it
37
+ # inside the block would raise NoMethodError.
38
+ # time_zone_options_for_select returns an HTML-safe buffer; Phlex's `safe`
39
+ # expects a plain String, so coerce with #to_s before marking it safe.
40
+ options_html = time_zone_options_for_select(@selected, @priority_zones, @zone_model).to_s
41
+
35
42
  render DaisyUI::Select.new(*daisy_modifiers, **select_attributes) do |el|
36
43
  render_placeholder(el) if @placeholder || @include_blank
37
- el.raw(el.safe(time_zone_options_for_select(@selected, @priority_zones, @zone_model)))
44
+ el.raw(el.safe(options_html))
38
45
  end
39
46
  end
40
47
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexForms
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson