pxs-forms 0.0.8 → 0.0.10

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: 324b3ef527145d19d5c6a532dfc4ee187d44f1dfbb4982e49638bd9e971be45c
4
- data.tar.gz: ac81d5570b80ff460e4d7f2264e06e1cc2aa10881a4722de455b1571dda73aab
3
+ metadata.gz: efd3c44a4990b55513ce3a025fa5a3e763667733668cdc3ecbd16859fec1629a
4
+ data.tar.gz: c3274a8654d27e4785b4ae937218dc5c48f12e283038b052ccaaf385df94c91b
5
5
  SHA512:
6
- metadata.gz: bf6f2f4f433ac338c0e269524222e35552a7ef9274de4fde57f5cedaf48d7cdc51006c009dac83d0c7b971fc4e4584968a7b6ed1fd78b30e815191cb3a44ad05
7
- data.tar.gz: 02c2b704d7d9fe619df0e0e160156cdaba5bdea9f245c028a1725e8ecc7c289b8f03d9ca636e1b2f22fd45d5c9ea0a8bf30ab7776e96d57c9a37a1be09fb5588
6
+ metadata.gz: f9eb444f40f1f9b869c29a2dfdb64f7206ea546f557296c880a704ce1d2f0d8ed5a3e1e2eef316dfdfafbcedf38735cf9df765d33e98cdf7ceba485ea3693b85
7
+ data.tar.gz: b529cad7defd4dc231af3a7e77324a54e7fb03c9c7df3ee2bf475f85dc6ec8410ca59d9d81ceb08b1d8d70ca9a942118177e5b8b5a527c111e8a242636fc1d86
@@ -2,30 +2,22 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
2
2
 
3
3
  delegate :tag, :safe_join, to: :@template
4
4
 
5
- # define a model field
6
- # the format is deduced from the column type or attribute name
7
5
  def field(attribute, options = {})
8
6
  @form_options = options
9
-
10
- # extract the object type from the attribute
11
7
  object_type = object_type_for_attribute(attribute)
12
8
 
13
- # set the input type depending on the attribute type
14
9
  input_type = case object_type
15
10
  when :date then :string
16
11
  when :integer then :string
17
12
  else object_type
18
13
  end
19
14
 
20
- # if as: :input_type is set, use it to set input type
21
15
  override_input_type = if options[:as]
22
16
  options[:as]
23
- # for collections, use a Select
24
17
  elsif options[:collection]
25
18
  :select
26
19
  end
27
20
 
28
- # return result of [input_type]_input method
29
21
  send("#{override_input_type || input_type}_input", attribute, options)
30
22
  end
31
23
 
@@ -57,7 +49,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
57
49
  field_block(attribute, options) do
58
50
  safe_join [
59
51
  (field_label(attribute, options[:label]) unless options[:label] == false),
60
- string_field(attribute, merge_input_options({class: "form-control #{"is-invalid" if has_error?(attribute)}"}, options[:input_html])),
52
+ string_field(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
61
53
  ]
62
54
  end
63
55
  end
@@ -66,7 +58,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
66
58
  field_block(attribute, options) do
67
59
  safe_join [
68
60
  (field_label(attribute, options[:label]) unless options[:label] == false),
69
- text_area(attribute, merge_input_options({class: "form-control #{"is-invalid" if has_error?(attribute)}"}, options[:input_html])),
61
+ text_area(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
70
62
  ]
71
63
  end
72
64
  end
@@ -75,7 +67,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
75
67
  field_block(attribute, options) do
76
68
  tag.div(class: "checkbox-field") do
77
69
  safe_join [
78
- check_box(attribute, merge_input_options({class: "checkbox-input"}, options[:input_html])),
70
+ check_box(attribute, merge_input_options({class: "checkbox-input"}, options)),
79
71
  label(attribute, options[:label], class: "checkbox-label"),
80
72
  ]
81
73
  end
@@ -93,16 +85,14 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
93
85
 
94
86
  def select_input(attribute, options = {})
95
87
 
96
- # default value method to :id
97
- value_method = options[:value_method] || :id
98
- # default text method to :name
99
- text_method = options[:text_method] || :name
100
- input_options = options[:input_html] || {}
88
+ value_method = options[:value_method] || :to_s
89
+ text_method = options[:text_method] || :to_s
90
+ input_options = options || {}
101
91
 
102
92
  multiple = input_options[:multiple]
103
93
 
104
94
  collection_input(attribute, options) do
105
- collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple} form-control #{"is-invalid" if has_error?(attribute)}"}, options[:input_html]))
95
+ collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple} #{"is-invalid" if has_error?(attribute)}"}, options))
106
96
  end
107
97
  end
108
98
 
@@ -110,7 +100,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
110
100
 
111
101
  # We probably need to go back later and adjust this for more customization
112
102
  collection_input(attribute, options) do
113
- grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select form-control #{"is-invalid" if has_error?(attribute)}"}, options[:input_html]))
103
+ grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select #{"is-invalid" if has_error?(attribute)}"}, options))
114
104
  end
115
105
  end
116
106
 
@@ -176,7 +166,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
176
166
  end
177
167
 
178
168
  def field_block(attribute, options = {}, &block)
179
- tag.div class: "field #{attribute}", id: options[:field_id] do
169
+ tag.div class: "field #{attribute}" do
180
170
  safe_join [
181
171
  block.call,
182
172
  hint_text(options[:hint]),
@@ -197,7 +187,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder
197
187
 
198
188
  def error_text(attribute)
199
189
  if has_error? attribute
200
- tag.div @object.errors[attribute].join("<br />").html_safe, class: "form-errors"
190
+ tag.div @object.errors[method].join("<br />").html_safe, class: "form-errors"
201
191
  end
202
192
  end
203
193
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pxs
4
4
  module Forms
5
- VERSION = "0.0.8"
5
+ VERSION = "0.0.10"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pxs-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Poubelle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-26 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: