chobble-forms 0.3.0
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 +7 -0
- data/README.md +3 -0
- data/lib/chobble-forms.rb +6 -0
- data/lib/engine.rb +21 -0
- data/lib/helpers.rb +206 -0
- data/lib/version.rb +3 -0
- data/views/chobble_forms/_auto_submit_select.html.erb +55 -0
- data/views/chobble_forms/_autocomplete_field.html.erb +17 -0
- data/views/chobble_forms/_checkbox.html.erb +12 -0
- data/views/chobble_forms/_comment.html.erb +40 -0
- data/views/chobble_forms/_comment_checkbox.html.erb +18 -0
- data/views/chobble_forms/_date_field.html.erb +15 -0
- data/views/chobble_forms/_decimal_comment.html.erb +58 -0
- data/views/chobble_forms/_display_field.html.erb +11 -0
- data/views/chobble_forms/_errors.html.erb +26 -0
- data/views/chobble_forms/_field_with_link.html.erb +33 -0
- data/views/chobble_forms/_fields.html.erb +9 -0
- data/views/chobble_forms/_fieldset.html.erb +29 -0
- data/views/chobble_forms/_file_field.html.erb +29 -0
- data/views/chobble_forms/_form_context.html.erb +74 -0
- data/views/chobble_forms/_header.html.erb +3 -0
- data/views/chobble_forms/_integer_comment.html.erb +58 -0
- data/views/chobble_forms/_number.html.erb +29 -0
- data/views/chobble_forms/_number_pass_fail_comment.html.erb +73 -0
- data/views/chobble_forms/_number_pass_fail_na_comment.html.erb +83 -0
- data/views/chobble_forms/_pass_fail.html.erb +14 -0
- data/views/chobble_forms/_pass_fail_comment.html.erb +47 -0
- data/views/chobble_forms/_pass_fail_na_comment.html.erb +49 -0
- data/views/chobble_forms/_radio_comment.html.erb +47 -0
- data/views/chobble_forms/_radio_pass_fail.html.erb +43 -0
- data/views/chobble_forms/_search_field.html.erb +15 -0
- data/views/chobble_forms/_select.html.erb +41 -0
- data/views/chobble_forms/_submit_button.html.erb +1 -0
- data/views/chobble_forms/_text_area.html.erb +22 -0
- data/views/chobble_forms/_text_field.html.erb +20 -0
- data/views/chobble_forms/_yes_no_radio.html.erb +15 -0
- data/views/chobble_forms/_yes_no_radio_comment.html.erb +48 -0
- metadata +186 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
<%
|
2
|
+
# Form wrapper that handles all form setup and context
|
3
|
+
# Required parameters:
|
4
|
+
# i18n_base: The i18n base path for translations
|
5
|
+
# Optional parameters:
|
6
|
+
# model: The model object (e.g., @inspection, @unit) - nil for non-model forms
|
7
|
+
# scope: The form scope for non-model forms (e.g., :session)
|
8
|
+
# url: Form submission URL (defaults to model's update path)
|
9
|
+
# method: HTTP method (defaults to :patch for models, :post for scoped forms)
|
10
|
+
# local: Use standard form submission instead of Turbo (defaults to false)
|
11
|
+
|
12
|
+
if model
|
13
|
+
url ||= url_for(model)
|
14
|
+
method ||= model.persisted? ? :patch : :post
|
15
|
+
else
|
16
|
+
# Non-model forms need explicit URL and default to POST
|
17
|
+
method ||= :post
|
18
|
+
end
|
19
|
+
|
20
|
+
# Check if local form submission is requested
|
21
|
+
use_local = local_assigns[:local] || false
|
22
|
+
%>
|
23
|
+
|
24
|
+
<% form_options = {
|
25
|
+
url: url,
|
26
|
+
method: method,
|
27
|
+
local: use_local,
|
28
|
+
html: {
|
29
|
+
multipart: true
|
30
|
+
}
|
31
|
+
} %>
|
32
|
+
|
33
|
+
<% unless use_local %>
|
34
|
+
<% form_options[:html][:data] = { turbo_stream: true } %>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<% if model
|
38
|
+
form_options[:model] = model
|
39
|
+
model_class_name = model.class.name
|
40
|
+
if model_class_name.include?('::')
|
41
|
+
form_options[:as] = model_class_name.demodulize.underscore.to_sym
|
42
|
+
end
|
43
|
+
elsif scope
|
44
|
+
form_options[:scope] = scope
|
45
|
+
end %>
|
46
|
+
|
47
|
+
<%= form_with(**form_options) do |form| %>
|
48
|
+
<%= render "chobble_forms/header",
|
49
|
+
title: I18n.t("#{i18n_base}.header")
|
50
|
+
%>
|
51
|
+
|
52
|
+
<% @_current_form = form %>
|
53
|
+
<% @_current_i18n_base = i18n_base %>
|
54
|
+
|
55
|
+
<%= yield form %>
|
56
|
+
|
57
|
+
<% if model && model.respond_to?(:errors) && model.errors.any? %>
|
58
|
+
<%= render 'chobble_forms/errors', model: model %>
|
59
|
+
<% end %>
|
60
|
+
|
61
|
+
<fieldset>
|
62
|
+
<% if local_assigns[:secondary_link_url].present? && local_assigns[:secondary_link_text].present? %>
|
63
|
+
<div class="form-actions">
|
64
|
+
<%= render 'chobble_forms/submit_button' %>
|
65
|
+
<%= link_to secondary_link_text, secondary_link_url, role: "button", class: "secondary" %>
|
66
|
+
</div>
|
67
|
+
<% else %>
|
68
|
+
<%= render 'chobble_forms/submit_button' %>
|
69
|
+
<% end %>
|
70
|
+
</fieldset>
|
71
|
+
|
72
|
+
<%# Save message display for Turbo Streams %>
|
73
|
+
<div id="form_save_message"></div>
|
74
|
+
<% end %>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for integer + comment fields with grid layout
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'trough_depth')
|
5
|
+
# Optional parameters:
|
6
|
+
# min: Minimum value
|
7
|
+
# max: Maximum value
|
8
|
+
# required: Whether the integer field is required (defaults to true)
|
9
|
+
# placeholder: Placeholder text
|
10
|
+
#
|
11
|
+
# This will render:
|
12
|
+
# - Integer field: field (e.g., 'trough_depth')
|
13
|
+
# - Comment field: field + '_comment' (e.g., 'trough_depth_comment')
|
14
|
+
|
15
|
+
integer_field = field
|
16
|
+
comment_field = "#{field}_comment".to_sym
|
17
|
+
|
18
|
+
form = @_current_form
|
19
|
+
model = form.object
|
20
|
+
|
21
|
+
field_data = form_field_setup(field, local_assigns)
|
22
|
+
|
23
|
+
integer_options = {
|
24
|
+
inputmode: "numeric",
|
25
|
+
pattern: "[0-9]*",
|
26
|
+
placeholder: field_data[:field_placeholder] || local_assigns[:placeholder],
|
27
|
+
required: local_assigns.fetch(:required, true),
|
28
|
+
class: "number"
|
29
|
+
}
|
30
|
+
|
31
|
+
if field_data[:prefilled]
|
32
|
+
integer_options[:value] = field_data[:value]
|
33
|
+
end
|
34
|
+
|
35
|
+
integer_options[:data] = {}
|
36
|
+
integer_options[:data][:min] = local_assigns[:min] if local_assigns[:min]
|
37
|
+
integer_options[:data][:max] = local_assigns[:max] if local_assigns[:max]
|
38
|
+
|
39
|
+
comment_info = comment_field_options(
|
40
|
+
form,
|
41
|
+
comment_field,
|
42
|
+
field_data[:field_label]
|
43
|
+
)
|
44
|
+
%>
|
45
|
+
|
46
|
+
<div class="form-grid number-comment" id="<%= integer_field %>">
|
47
|
+
<%= form.label integer_field, field_data[:field_label], class: "label" %>
|
48
|
+
<%= form.text_field integer_field, integer_options %>
|
49
|
+
|
50
|
+
<%= render 'chobble_forms/comment_checkbox',
|
51
|
+
comment_field: comment_field,
|
52
|
+
checkbox_id: comment_info[:checkbox_id],
|
53
|
+
textarea_id: comment_info[:options][:id],
|
54
|
+
has_comment: comment_info[:has_comment],
|
55
|
+
prefilled: comment_info[:prefilled] %>
|
56
|
+
|
57
|
+
<%= form.text_area comment_field, comment_info[:options] %>
|
58
|
+
</div>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%
|
2
|
+
# Get i18n_base from section (already validated there)
|
3
|
+
setup = form_field_setup(field, local_assigns)
|
4
|
+
|
5
|
+
step ||= 0.01
|
6
|
+
min ||= nil
|
7
|
+
max ||= nil
|
8
|
+
required ||= false
|
9
|
+
|
10
|
+
field_options = {
|
11
|
+
step: step,
|
12
|
+
min: min,
|
13
|
+
max: max,
|
14
|
+
required: required,
|
15
|
+
placeholder: setup[:field_placeholder]
|
16
|
+
}
|
17
|
+
|
18
|
+
if setup[:prefilled]
|
19
|
+
field_options[:value] = setup[:value]
|
20
|
+
end
|
21
|
+
%>
|
22
|
+
|
23
|
+
<div class="number-field" id="<%= field %>">
|
24
|
+
<%= setup[:form_object].label field, setup[:field_label] %>
|
25
|
+
<%= setup[:form_object].number_field field, field_options.compact %>
|
26
|
+
<% if setup[:field_hint].present? %>
|
27
|
+
<small class="form-text"><%= setup[:field_hint] %></small>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for number + pass/fail + comment fields
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'slide_platform_height')
|
5
|
+
# Optional parameters (passed through to number field):
|
6
|
+
# step: Step value for number input (default: 0.01)
|
7
|
+
# min: Minimum value
|
8
|
+
# max: Maximum value
|
9
|
+
# required: Whether the number field is required
|
10
|
+
#
|
11
|
+
# This will render:
|
12
|
+
# - Number field: field (e.g., 'slide_platform_height')
|
13
|
+
# - Pass/fail field: field + '_pass' (e.g., 'slide_platform_height_pass')
|
14
|
+
# - Comment field: field + '_comment' (e.g., 'slide_platform_height_comment')
|
15
|
+
|
16
|
+
number_field = field
|
17
|
+
pass_fail_field = "#{field}_pass".to_sym
|
18
|
+
comment_field = "#{field}_comment".to_sym
|
19
|
+
|
20
|
+
number_options = local_assigns.slice(:step, :min, :max, :required)
|
21
|
+
|
22
|
+
form = @_current_form
|
23
|
+
model = form.object
|
24
|
+
|
25
|
+
field_data = form_field_setup(field, local_assigns)
|
26
|
+
number_options[:value] = field_data[:value]
|
27
|
+
|
28
|
+
pass_fail_value, pass_fail_prefilled = get_field_value_and_prefilled_status(
|
29
|
+
form,
|
30
|
+
pass_fail_field
|
31
|
+
)
|
32
|
+
pass_fail_checked = pass_fail_prefilled ? pass_fail_value : nil
|
33
|
+
|
34
|
+
comment_info = comment_field_options(
|
35
|
+
form,
|
36
|
+
comment_field,
|
37
|
+
field_data[:field_label]
|
38
|
+
)
|
39
|
+
%>
|
40
|
+
|
41
|
+
<div class="form-grid number-radio-comment" id="<%= number_field %>">
|
42
|
+
<label for="<%= form.field_id(number_field) %>" class="label">
|
43
|
+
<%= field_data[:field_label] %>
|
44
|
+
</label>
|
45
|
+
|
46
|
+
<%= form.number_field number_field,
|
47
|
+
id: form.field_id(number_field),
|
48
|
+
step: number_options[:step] || 0.1,
|
49
|
+
min: number_options[:min],
|
50
|
+
max: number_options[:max],
|
51
|
+
required: number_options[:required],
|
52
|
+
placeholder: field_data[:field_placeholder],
|
53
|
+
value: number_options[:value],
|
54
|
+
class: "number"
|
55
|
+
%>
|
56
|
+
|
57
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
58
|
+
field: pass_fail_field,
|
59
|
+
prefilled: pass_fail_prefilled,
|
60
|
+
checked_value: pass_fail_checked
|
61
|
+
%>
|
62
|
+
|
63
|
+
<%= render 'chobble_forms/comment_checkbox',
|
64
|
+
comment_field: comment_field,
|
65
|
+
checkbox_id: comment_info[:checkbox_id],
|
66
|
+
textarea_id: comment_info[:options][:id],
|
67
|
+
has_comment: comment_info[:has_comment],
|
68
|
+
prefilled: comment_info[:prefilled] %>
|
69
|
+
|
70
|
+
<%= form.text_area comment_field,
|
71
|
+
comment_info[:options]
|
72
|
+
%>
|
73
|
+
</div>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for number + pass/fail + N/A + comment fields
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'slide_platform_height')
|
5
|
+
# Optional parameters (passed through to number field):
|
6
|
+
# step: Step value for number input (default: 0.01)
|
7
|
+
# min: Minimum value
|
8
|
+
# max: Maximum value
|
9
|
+
# required: Whether the number field is required
|
10
|
+
#
|
11
|
+
# This will render:
|
12
|
+
# - Number field: field (e.g., 'slide_platform_height')
|
13
|
+
# - Pass/fail field: field + '_pass' (e.g., 'slide_platform_height_pass')
|
14
|
+
# - Pass = true, Fail = false, N/A = 2 (but rendered as checkbox)
|
15
|
+
# - Comment field: field + '_comment' (e.g., 'slide_platform_height_comment')
|
16
|
+
|
17
|
+
number_field = field
|
18
|
+
pass_fail_field = "#{field}_pass".to_sym
|
19
|
+
comment_field = "#{field}_comment".to_sym
|
20
|
+
|
21
|
+
number_options = local_assigns.slice(:step, :min, :max, :required)
|
22
|
+
|
23
|
+
form = @_current_form
|
24
|
+
model = form.object
|
25
|
+
|
26
|
+
field_data = form_field_setup(field, local_assigns)
|
27
|
+
number_options[:value] = field_data[:value]
|
28
|
+
|
29
|
+
pass_fail_value, pass_fail_prefilled = get_field_value_and_prefilled_status(
|
30
|
+
form,
|
31
|
+
pass_fail_field
|
32
|
+
)
|
33
|
+
|
34
|
+
# Debug: Check if the model value is being read correctly
|
35
|
+
model_value = model.send(pass_fail_field) if model.respond_to?(pass_fail_field)
|
36
|
+
actual_value = pass_fail_prefilled ? pass_fail_value : model_value
|
37
|
+
na_checked = actual_value == 2
|
38
|
+
pass_fail_checked = na_checked ? nil : actual_value
|
39
|
+
|
40
|
+
comment_info = comment_field_options(
|
41
|
+
form,
|
42
|
+
comment_field,
|
43
|
+
field_data[:field_label]
|
44
|
+
)
|
45
|
+
|
46
|
+
pass_fail_id = form.field_id(pass_fail_field)
|
47
|
+
na_checkbox_id = "#{field}_pass_na_checkbox"
|
48
|
+
%>
|
49
|
+
|
50
|
+
<div class="form-grid number-radio-comment" id="<%= number_field %>">
|
51
|
+
<label for="<%= form.field_id(number_field) %>" class="label">
|
52
|
+
<%= field_data[:field_label] %>
|
53
|
+
</label>
|
54
|
+
|
55
|
+
<%= form.number_field number_field,
|
56
|
+
id: form.field_id(number_field),
|
57
|
+
step: number_options[:step] || 0.1,
|
58
|
+
min: number_options[:min],
|
59
|
+
max: number_options[:max],
|
60
|
+
required: number_options[:required],
|
61
|
+
placeholder: field_data[:field_placeholder],
|
62
|
+
value: number_options[:value],
|
63
|
+
class: "number"
|
64
|
+
%>
|
65
|
+
|
66
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
67
|
+
field: pass_fail_field,
|
68
|
+
prefilled: pass_fail_prefilled && !na_checked,
|
69
|
+
checked_value: pass_fail_checked
|
70
|
+
%>
|
71
|
+
|
72
|
+
|
73
|
+
<%= render 'chobble_forms/comment_checkbox',
|
74
|
+
comment_field: comment_field,
|
75
|
+
checkbox_id: comment_info[:checkbox_id],
|
76
|
+
textarea_id: comment_info[:options][:id],
|
77
|
+
has_comment: comment_info[:has_comment],
|
78
|
+
prefilled: comment_info[:prefilled] %>
|
79
|
+
|
80
|
+
<%= form.text_area comment_field,
|
81
|
+
comment_info[:options]
|
82
|
+
%>
|
83
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%
|
2
|
+
form = @_current_form
|
3
|
+
field_data = form_field_setup(field, local_assigns)
|
4
|
+
checked_value = field_data[:prefilled] ? field_data[:value] : nil
|
5
|
+
%>
|
6
|
+
|
7
|
+
<div class="form-grid radio-comment" id="<%= field %>">
|
8
|
+
<label class=label><%= field_data[:field_label] %></label>
|
9
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
10
|
+
field: field,
|
11
|
+
prefilled: field_data[:prefilled],
|
12
|
+
checked_value: checked_value
|
13
|
+
%>
|
14
|
+
</div>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for pass/fail + comment fields with grid layout
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'seam_integrity_pass')
|
5
|
+
#
|
6
|
+
# This will render:
|
7
|
+
# - Pass/fail field: field (e.g., 'seam_integrity_pass')
|
8
|
+
# - Comment field: base field + '_comment' (e.g., 'seam_integrity_comment')
|
9
|
+
|
10
|
+
base_field = field.to_s.gsub(/_pass$/, "")
|
11
|
+
comment_field = "#{base_field}_comment".to_sym
|
12
|
+
|
13
|
+
form = @_current_form
|
14
|
+
model = form.object
|
15
|
+
|
16
|
+
field_data = form_field_setup(field, local_assigns)
|
17
|
+
|
18
|
+
comment_info = comment_field_options(
|
19
|
+
form,
|
20
|
+
comment_field,
|
21
|
+
field_data[:field_label]
|
22
|
+
)
|
23
|
+
|
24
|
+
checked_value = field_data[:prefilled] ? field_data[:value] : nil
|
25
|
+
%>
|
26
|
+
|
27
|
+
<div class="form-grid radio-comment" id="<%= field %>">
|
28
|
+
<label class="label">
|
29
|
+
<%= field_data[:field_label] %>
|
30
|
+
</label>
|
31
|
+
|
32
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
33
|
+
field: field,
|
34
|
+
prefilled: field_data[:prefilled],
|
35
|
+
checked_value: checked_value
|
36
|
+
%>
|
37
|
+
|
38
|
+
<%= render 'chobble_forms/comment_checkbox',
|
39
|
+
comment_field: comment_field,
|
40
|
+
checkbox_id: comment_info[:checkbox_id],
|
41
|
+
textarea_id: comment_info[:options][:id],
|
42
|
+
has_comment: comment_info[:has_comment],
|
43
|
+
prefilled: comment_info[:prefilled]
|
44
|
+
%>
|
45
|
+
|
46
|
+
<%= form.text_area comment_field, comment_info[:options] %>
|
47
|
+
</div>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for pass/fail + N/A + comment fields with grid layout
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'seam_integrity_pass')
|
5
|
+
#
|
6
|
+
# This will render:
|
7
|
+
# - Pass/fail/N/A field: field (e.g., 'seam_integrity_pass')
|
8
|
+
# - Enum fields: Pass = "pass", Fail = "fail", N/A = "na" (rendered as radio buttons)
|
9
|
+
# - Boolean fields: Pass = true, Fail = false (rendered as radio buttons)
|
10
|
+
# - Comment field: base field + '_comment' (e.g., 'seam_integrity_comment')
|
11
|
+
|
12
|
+
base_field = field.to_s.gsub(/_pass$/, "")
|
13
|
+
comment_field = "#{base_field}_comment".to_sym
|
14
|
+
|
15
|
+
form = @_current_form
|
16
|
+
model = form.object
|
17
|
+
|
18
|
+
field_data = form_field_setup(field, local_assigns)
|
19
|
+
|
20
|
+
comment_info = comment_field_options(
|
21
|
+
form,
|
22
|
+
comment_field,
|
23
|
+
field_data[:field_label]
|
24
|
+
)
|
25
|
+
|
26
|
+
checked_value = field_data[:prefilled] ? field_data[:value] : nil
|
27
|
+
%>
|
28
|
+
|
29
|
+
<div class="form-grid radio-comment" id="<%= field %>">
|
30
|
+
<label class="label">
|
31
|
+
<%= field_data[:field_label] %>
|
32
|
+
</label>
|
33
|
+
|
34
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
35
|
+
field: field,
|
36
|
+
prefilled: field_data[:prefilled],
|
37
|
+
checked_value: checked_value
|
38
|
+
%>
|
39
|
+
|
40
|
+
<%= render 'chobble_forms/comment_checkbox',
|
41
|
+
comment_field: comment_field,
|
42
|
+
checkbox_id: comment_info[:checkbox_id],
|
43
|
+
textarea_id: comment_info[:options][:id],
|
44
|
+
has_comment: comment_info[:has_comment],
|
45
|
+
prefilled: comment_info[:prefilled]
|
46
|
+
%>
|
47
|
+
|
48
|
+
<%= form.text_area comment_field, comment_info[:options] %>
|
49
|
+
</div>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<%
|
2
|
+
# Composite partial for radio + comment fields with grid layout
|
3
|
+
# Required parameters:
|
4
|
+
# field: Base field name (e.g., 'permanent_roof')
|
5
|
+
#
|
6
|
+
# This will render:
|
7
|
+
# - Radio field: field with Yes (true) / No (false) options
|
8
|
+
# - Comment field: field + '_comment' (e.g., 'permanent_roof_comment')
|
9
|
+
|
10
|
+
radio_field = field
|
11
|
+
comment_field = "#{field}_comment".to_sym
|
12
|
+
|
13
|
+
form = @_current_form
|
14
|
+
model = form.object
|
15
|
+
|
16
|
+
field_data = form_field_setup(field, local_assigns)
|
17
|
+
|
18
|
+
comment_info = comment_field_options(
|
19
|
+
form,
|
20
|
+
comment_field,
|
21
|
+
field_data[:field_label]
|
22
|
+
)
|
23
|
+
|
24
|
+
checked_value = field_data[:prefilled] ? field_data[:value] : nil
|
25
|
+
%>
|
26
|
+
|
27
|
+
<div class="form-grid radio-comment">
|
28
|
+
<label class="wrapper">
|
29
|
+
<%= field_data[:field_label] %>
|
30
|
+
</label>
|
31
|
+
|
32
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
33
|
+
field: radio_field,
|
34
|
+
prefilled: field_data[:prefilled],
|
35
|
+
checked_value: checked_value
|
36
|
+
%>
|
37
|
+
|
38
|
+
<%= render 'chobble_forms/comment_checkbox',
|
39
|
+
comment_field: comment_field,
|
40
|
+
checkbox_id: comment_info[:checkbox_id],
|
41
|
+
textarea_id: comment_info[:options][:id],
|
42
|
+
has_comment: comment_info[:has_comment],
|
43
|
+
prefilled: comment_info[:prefilled]
|
44
|
+
%>
|
45
|
+
|
46
|
+
<%= form.text_area comment_field, comment_info[:options] %>
|
47
|
+
</div>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%
|
2
|
+
form = @_current_form
|
3
|
+
yes_no ||= false
|
4
|
+
|
5
|
+
# Check if this field is an enum by looking at the model
|
6
|
+
model = form.object
|
7
|
+
is_enum = model.class.respond_to?(:defined_enums) && model.class.defined_enums.key?(field.to_s)
|
8
|
+
|
9
|
+
if is_enum
|
10
|
+
pass_value = "pass"
|
11
|
+
fail_value = "fail"
|
12
|
+
na_value = "na"
|
13
|
+
else
|
14
|
+
pass_value = true
|
15
|
+
fail_value = false
|
16
|
+
end
|
17
|
+
%>
|
18
|
+
|
19
|
+
<div class="pass-fail" id="<%= field %>">
|
20
|
+
<label>
|
21
|
+
<%= t("shared.#{yes_no ? "yes" : "pass"}") %>
|
22
|
+
<%= form.radio_button field,
|
23
|
+
pass_value,
|
24
|
+
radio_button_options(prefilled, checked_value, pass_value)
|
25
|
+
%>
|
26
|
+
</label>
|
27
|
+
<label>
|
28
|
+
<%= form.radio_button field,
|
29
|
+
fail_value,
|
30
|
+
radio_button_options(prefilled, checked_value, fail_value)
|
31
|
+
%>
|
32
|
+
<%= t("shared.#{yes_no ? "no" : "fail"}") %>
|
33
|
+
</label>
|
34
|
+
<% if is_enum %>
|
35
|
+
<label>
|
36
|
+
<%= form.radio_button field,
|
37
|
+
na_value,
|
38
|
+
radio_button_options(prefilled, checked_value, na_value)
|
39
|
+
%>
|
40
|
+
<%= t("shared.not_applicable") %>
|
41
|
+
</label>
|
42
|
+
<% end %>
|
43
|
+
</div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%
|
2
|
+
# Search form options
|
3
|
+
url = local_assigns[:url] or raise ArgumentError, "url is required for search field"
|
4
|
+
placeholder = local_assigns[:placeholder] || "Search..."
|
5
|
+
field_name = local_assigns[:field_name] || :query
|
6
|
+
submit_text = local_assigns[:submit_text] || "Search"
|
7
|
+
css_class = local_assigns[:css_class] || "search-form"
|
8
|
+
%>
|
9
|
+
|
10
|
+
<div class="<%= css_class %>">
|
11
|
+
<%= form_with url: url, method: :get do |form| %>
|
12
|
+
<%= form.text_field field_name, placeholder: placeholder, value: params[field_name] %>
|
13
|
+
<%= form.submit submit_text %>
|
14
|
+
<% end %>
|
15
|
+
</div>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<%
|
2
|
+
# Get i18n_base from section (already validated there)
|
3
|
+
setup = form_field_setup(field, local_assigns)
|
4
|
+
|
5
|
+
# Form field options
|
6
|
+
required ||= false
|
7
|
+
|
8
|
+
# Options should be:
|
9
|
+
# - For select: options_for_select array or collection_select params
|
10
|
+
# - For collection_select: [collection, value_method, text_method]
|
11
|
+
options ||= []
|
12
|
+
collection_select_params = local_assigns[:collection_select_params]
|
13
|
+
prompt = local_assigns[:prompt]
|
14
|
+
|
15
|
+
# Build select options
|
16
|
+
select_options = {}
|
17
|
+
select_options[:prompt] = prompt if prompt
|
18
|
+
|
19
|
+
# Build field options
|
20
|
+
field_options = { required: required }.compact
|
21
|
+
|
22
|
+
# Add any additional HTML attributes
|
23
|
+
field_options[:onchange] = local_assigns[:onchange] if local_assigns[:onchange]
|
24
|
+
%>
|
25
|
+
|
26
|
+
<%= setup[:form_object].label field, setup[:field_label] %>
|
27
|
+
<% if collection_select_params %>
|
28
|
+
<%= setup[:form_object].collection_select(
|
29
|
+
field,
|
30
|
+
collection_select_params[:collection],
|
31
|
+
collection_select_params[:value_method],
|
32
|
+
collection_select_params[:text_method],
|
33
|
+
select_options,
|
34
|
+
field_options
|
35
|
+
) %>
|
36
|
+
<% else %>
|
37
|
+
<%= setup[:form_object].select field, options, select_options, field_options %>
|
38
|
+
<% end %>
|
39
|
+
<% if setup[:field_hint].present? %>
|
40
|
+
<small><%= setup[:field_hint] %></small>
|
41
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @_current_form.submit t("#{@_current_i18n_base}.submit", raise: true) %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%
|
2
|
+
setup = form_field_setup(field, local_assigns)
|
3
|
+
|
4
|
+
rows ||= 4
|
5
|
+
required ||= false
|
6
|
+
|
7
|
+
field_options = {
|
8
|
+
rows: rows,
|
9
|
+
placeholder: setup[:field_placeholder],
|
10
|
+
required: required
|
11
|
+
}.compact
|
12
|
+
|
13
|
+
if setup[:prefilled]
|
14
|
+
field_options[:value] = setup[:value]
|
15
|
+
end
|
16
|
+
%>
|
17
|
+
|
18
|
+
<%= setup[:form_object].label field, setup[:field_label] %>
|
19
|
+
<%= setup[:form_object].text_area field, field_options %>
|
20
|
+
<% if setup[:field_hint].present? %>
|
21
|
+
<small><%= setup[:field_hint] %></small>
|
22
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%
|
2
|
+
setup = form_field_setup(field, local_assigns)
|
3
|
+
|
4
|
+
field_type = local_assigns[:type] || :text_field
|
5
|
+
required ||= false
|
6
|
+
|
7
|
+
field_options = {
|
8
|
+
required:,
|
9
|
+
accept: local_assigns[:accept],
|
10
|
+
value: setup[:value]
|
11
|
+
}
|
12
|
+
%>
|
13
|
+
|
14
|
+
<%= setup[:form_object].label field, id: field do %>
|
15
|
+
<%= setup[:field_label] %>
|
16
|
+
<%= setup[:form_object].send(field_type, field, field_options) %>
|
17
|
+
<% if local_assigns[:help_text] %>
|
18
|
+
<small class="help-text"><%= local_assigns[:help_text] %></small>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%
|
2
|
+
form = @_current_form
|
3
|
+
field_data = form_field_setup(field, local_assigns)
|
4
|
+
checked_value = field_data[:prefilled] ? field_data[:value] : nil
|
5
|
+
%>
|
6
|
+
|
7
|
+
<div class="form-grid radio-comment" id="<%= field %>">
|
8
|
+
<label class="label"><%= field_data[:field_label] %></label>
|
9
|
+
<%= render 'chobble_forms/radio_pass_fail',
|
10
|
+
field: field,
|
11
|
+
prefilled: field_data[:prefilled],
|
12
|
+
checked_value: checked_value,
|
13
|
+
yes_no: true
|
14
|
+
%>
|
15
|
+
</div>
|