chobble-forms 0.7.0 → 0.7.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: 114cd63966175b3b8f30be99441ff3da688526f9e46bc0b08c9add531c93d8eb
4
- data.tar.gz: 225988209e98465f4c92d14729ad9650878519d1563cea5486f90b3342d8a28e
3
+ metadata.gz: 6541e97cfb901cd5437021bc314615f055125057456dfad79475be9497c55092
4
+ data.tar.gz: 21a7944f64c0974e144cfbc0b39fcb4d0f7dcff980358b08454c899ef181d8a3
5
5
  SHA512:
6
- metadata.gz: 934333541f43b3fd5f8f0c24468f15a1d755b5567c0c341a856c6fedb67932f2a606d93452741ca26531a107d30cbd21363f1ec27f4acc7059a001edc3ca42ac
7
- data.tar.gz: 535ab94d5f12ca207fd4c34d198e3938161465112819c0df18ea8cfa7c8f33ab29d8f44e9112aab6a011bf1889e49cf99e527223dadcdcb920f41830dbea7065
6
+ metadata.gz: 47ddc8c257e2e6b228205fbe2f6ac215b5d43d51e1df0f4348f912b94f1d153f2b0d810db04ef6531c71c30b0f69ad12b29a4d9ab74b4a5be7af60bf56237f2a
7
+ data.tar.gz: f30b8deb1d9ad611671be7a3fc92d41e37e36613b6a6d294cef1c28e46ef402bd495820b5a7b1bd0e989e987729defb196292c17dc20a258a3b88b3c437e2a92
@@ -7,11 +7,11 @@ module ChobbleForms
7
7
  module Helpers
8
8
  extend T::Sig
9
9
 
10
- SelectOption = T.type_alias {
10
+ SelectOption = T.type_alias do
11
11
  [String, T.any(String, Integer)]
12
- }
12
+ end
13
13
 
14
- LocalAssignValue = T.type_alias {
14
+ LocalAssignValue = T.type_alias do
15
15
  T.any(
16
16
  String,
17
17
  Symbol,
@@ -21,9 +21,9 @@ module ChobbleForms
21
21
  T::Array[SelectOption],
22
22
  T::Hash[Symbol, T.untyped]
23
23
  )
24
- }
24
+ end
25
25
 
26
- FieldSetupResult = T.type_alias {
26
+ FieldSetupResult = T.type_alias do
27
27
  {
28
28
  form_object: T.untyped,
29
29
  i18n_base: String,
@@ -33,7 +33,7 @@ module ChobbleForms
33
33
  field_hint: T.nilable(String),
34
34
  field_placeholder: T.nilable(String)
35
35
  }
36
- }
36
+ end
37
37
 
38
38
  sig { params(field: Symbol, local_assigns: T::Hash[Symbol, LocalAssignValue]).returns(FieldSetupResult) }
39
39
  def form_field_setup(field, local_assigns)
@@ -91,7 +91,10 @@ module ChobbleForms
91
91
  }
92
92
  end
93
93
 
94
- sig { params(prefilled: T::Boolean, checked_value: T.untyped, expected_value: T.untyped).returns(T::Hash[Symbol, T::Boolean]) }
94
+ sig do
95
+ params(prefilled: T::Boolean, checked_value: T.untyped,
96
+ expected_value: T.untyped).returns(T::Hash[Symbol, T::Boolean])
97
+ end
95
98
  def radio_button_options(prefilled, checked_value, expected_value)
96
99
  (prefilled && checked_value == expected_value) ? {checked: true} : {}
97
100
  end
@@ -135,8 +138,13 @@ module ChobbleForms
135
138
  def build_field_translations(field)
136
139
  i18n_base = T.unsafe(instance_variable_get(:@_current_i18n_base))
137
140
 
138
- field_without_suffix = FieldUtils.strip_field_suffix(field)
139
- fields_key = "#{i18n_base}.fields.#{field_without_suffix}"
141
+ # Only strip _pass suffix for pass/fail fields, not _comment fields
142
+ lookup_field = if field.to_s.end_with?("_pass")
143
+ FieldUtils.strip_field_suffix(field)
144
+ else
145
+ field
146
+ end
147
+ fields_key = "#{i18n_base}.fields.#{lookup_field}"
140
148
  field_label = t(fields_key, raise: true)
141
149
 
142
150
  base_parts = i18n_base.split(".")
@@ -151,7 +159,10 @@ module ChobbleForms
151
159
  }
152
160
  end
153
161
 
154
- sig { params(field_translations: T::Hash[Symbol, T.nilable(String)], value: T.untyped, prefilled: T::Boolean).returns(FieldSetupResult) }
162
+ sig do
163
+ params(field_translations: T::Hash[Symbol, T.nilable(String)], value: T.untyped,
164
+ prefilled: T::Boolean).returns(FieldSetupResult)
165
+ end
155
166
  def build_field_setup_result(field_translations, value, prefilled)
156
167
  form_obj = T.unsafe(instance_variable_get(:@_current_form))
157
168
  i18n_base = T.unsafe(instance_variable_get(:@_current_i18n_base))
@@ -167,13 +178,28 @@ module ChobbleForms
167
178
  )
168
179
  end
169
180
 
181
+ sig { params(model: T.untyped, field: Symbol, raise_if_missing: T::Boolean).returns(T.untyped) }
182
+ def get_field_value_from_model(model, field, raise_if_missing: false)
183
+ return nil unless model
184
+
185
+ # Check for base field first (for fields like step_ramp_size that have a base value)
186
+ # Only check for _pass suffix if base field doesn't exist (for pass_fail_comment partials)
187
+ if model.respond_to?(field)
188
+ model.send(field)
189
+ elsif model.respond_to?("#{field}_pass")
190
+ model.send("#{field}_pass")
191
+ elsif raise_if_missing
192
+ available = model.attributes.keys.sort.join(", ")
193
+ raise "Field '#{field}' or '#{field}_pass' not found on " \
194
+ "#{model.class.name}. Available fields: #{available}"
195
+ end
196
+ end
197
+
170
198
  sig { params(model: T.untyped, field: Symbol).returns({value: T.untyped, prefilled: T::Boolean}) }
171
199
  def resolve_field_value(model, field)
172
- field_str = field.to_s
200
+ return {value: nil, prefilled: false} if field.to_s.include?("password")
173
201
 
174
- return {value: nil, prefilled: false} if field_str.include?("password")
175
-
176
- current_value = model.send(field) if model.respond_to?(field)
202
+ current_value = get_field_value_from_model(model, field, raise_if_missing: true)
177
203
 
178
204
  # Check if this field should not be prefilled based on excluded fields list
179
205
  excluded_fields = T.unsafe(instance_variable_get(:@_excluded_prefill_fields))
@@ -189,11 +215,7 @@ module ChobbleForms
189
215
  }
190
216
  end
191
217
 
192
- if field_str.end_with?("_id") && field_str != "id"
193
- resolve_association_value(model, field_str)
194
- else
195
- {value: current_value, prefilled: false}
196
- end
218
+ {value: current_value, prefilled: false}
197
219
  end
198
220
 
199
221
  sig { params(previous_inspection: T.untyped, current_model: T.untyped, field: Symbol).returns(T.untyped) }
@@ -203,7 +225,7 @@ module ChobbleForms
203
225
  elsif current_model.class.name.include?("Assessment")
204
226
  assessment_type = current_model.class.name.demodulize.underscore
205
227
  previous_model = previous_inspection.send(assessment_type)
206
- previous_model&.send(field)
228
+ get_field_value_from_model(previous_model, field, raise_if_missing: false)
207
229
  else
208
230
  previous_inspection.send(field)
209
231
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module ChobbleForms
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.2"
6
6
  end
@@ -1,13 +1,14 @@
1
1
  <%
2
2
  # Composite partial for pass/fail + comment fields with grid layout
3
3
  # Required parameters:
4
- # field: Base field name (e.g., 'seam_integrity_pass')
4
+ # field: Base field name (e.g., 'seam_integrity')
5
5
  #
6
6
  # This will render:
7
- # - Pass/fail field: field (e.g., 'seam_integrity_pass')
7
+ # - Pass/fail field: base field + '_pass' (e.g., 'seam_integrity_pass')
8
8
  # - Comment field: base field + '_comment' (e.g., 'seam_integrity_comment')
9
9
 
10
10
  base_field = field.to_s.gsub(/_pass$/, "")
11
+ pass_field = "#{base_field}_pass".to_sym
11
12
  comment_field = "#{base_field}_comment".to_sym
12
13
 
13
14
  form = @_current_form
@@ -30,7 +31,7 @@
30
31
  </label>
31
32
 
32
33
  <%= render 'chobble_forms/radio_pass_fail',
33
- field: field,
34
+ field: pass_field,
34
35
  prefilled: field_data[:prefilled],
35
36
  checked_value: checked_value %>
36
37
 
@@ -1,15 +1,16 @@
1
1
  <%
2
2
  # Composite partial for pass/fail + N/A + comment fields with grid layout
3
3
  # Required parameters:
4
- # field: Base field name (e.g., 'seam_integrity_pass')
4
+ # field: Base field name (e.g., 'seam_integrity')
5
5
  #
6
6
  # This will render:
7
- # - Pass/fail/N/A field: field (e.g., 'seam_integrity_pass')
7
+ # - Pass/fail/N/A field: base field + '_pass' (e.g., 'seam_integrity_pass')
8
8
  # - Enum fields: Pass = "pass", Fail = "fail", N/A = "na" (rendered as radio buttons)
9
9
  # - Boolean fields: Pass = true, Fail = false (rendered as radio buttons)
10
10
  # - Comment field: base field + '_comment' (e.g., 'seam_integrity_comment')
11
11
 
12
12
  base_field = field.to_s.gsub(/_pass$/, "")
13
+ pass_field = "#{base_field}_pass".to_sym
13
14
  comment_field = "#{base_field}_comment".to_sym
14
15
 
15
16
  form = @_current_form
@@ -31,7 +32,7 @@
31
32
  </label>
32
33
 
33
34
  <%= render 'chobble_forms/radio_pass_fail',
34
- field: field,
35
+ field: pass_field,
35
36
  prefilled: field_data[:prefilled],
36
37
  checked_value: checked_value %>
37
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chobble-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chobble.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-16 00:00:00.000000000 Z
11
+ date: 2025-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails