formstrap 0.1.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/.DS_Store +0 -0
- data/.gitignore +33 -0
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +28 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +10 -0
- data/app/assets/config/headmin_manifest.js +2 -0
- data/app/assets/images/avatar.jpg +0 -0
- data/app/assets/images/document.docx +0 -0
- data/app/assets/images/document.pdf +0 -0
- data/app/assets/images/image.jpg +0 -0
- data/app/assets/images/spreadsheet.xls +0 -0
- data/app/assets/images/video.mp4 +0 -0
- data/app/assets/javascripts/formstrap/config/i18n.js +11 -0
- data/app/assets/javascripts/formstrap/controllers/autocomplete_controller.js +318 -0
- data/app/assets/javascripts/formstrap/controllers/date_range_controller.js +38 -0
- data/app/assets/javascripts/formstrap/controllers/dropzone_controller.js +31 -0
- data/app/assets/javascripts/formstrap/controllers/file_preview_controller.js +244 -0
- data/app/assets/javascripts/formstrap/controllers/flatpickr_controller.js +35 -0
- data/app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js +28 -0
- data/app/assets/javascripts/formstrap/controllers/media_controller.js +252 -0
- data/app/assets/javascripts/formstrap/controllers/media_modal_controller.js +147 -0
- data/app/assets/javascripts/formstrap/controllers/redactorx_controller.js +40 -0
- data/app/assets/javascripts/formstrap/controllers/repeater_controller.js +148 -0
- data/app/assets/javascripts/formstrap/controllers/select_controller.js +49 -0
- data/app/assets/javascripts/formstrap/controllers/textarea_controller.js +48 -0
- data/app/assets/javascripts/formstrap/index.js +32 -0
- data/app/assets/javascripts/formstrap.js +11515 -0
- data/app/assets/stylesheets/formstrap/forms/autocomplete.scss +27 -0
- data/app/assets/stylesheets/formstrap/forms/file.scss +83 -0
- data/app/assets/stylesheets/formstrap/forms/media.scss +10 -0
- data/app/assets/stylesheets/formstrap/forms/repeater.scss +62 -0
- data/app/assets/stylesheets/formstrap/forms/search.scss +12 -0
- data/app/assets/stylesheets/formstrap/forms.scss +12 -0
- data/app/assets/stylesheets/formstrap/general.scss +18 -0
- data/app/assets/stylesheets/formstrap/media/index.scss +9 -0
- data/app/assets/stylesheets/formstrap/media.scss +1 -0
- data/app/assets/stylesheets/formstrap/utilities/buttons.scss +27 -0
- data/app/assets/stylesheets/formstrap/utilities/dropzone.scss +72 -0
- data/app/assets/stylesheets/formstrap/utilities.scss +2 -0
- data/app/assets/stylesheets/formstrap/vendor/flatpickr.css +903 -0
- data/app/assets/stylesheets/formstrap/vendor/tom-select-bootstrap.scss +535 -0
- data/app/assets/stylesheets/formstrap.css +1559 -0
- data/app/assets/stylesheets/formstrap.scss +11 -0
- data/app/controllers/concerns/formstrap/pagination.rb +27 -0
- data/app/controllers/formstrap/media_controller.rb +68 -0
- data/app/controllers/formstrap_controller.rb +2 -0
- data/app/models/concerns/formstrap/autocompletable.rb +36 -0
- data/app/models/concerns/formstrap/hintable.rb +22 -0
- data/app/models/concerns/formstrap/input_groupable.rb +21 -0
- data/app/models/concerns/formstrap/labelable.rb +31 -0
- data/app/models/concerns/formstrap/listable.rb +26 -0
- data/app/models/concerns/formstrap/placeholderable.rb +11 -0
- data/app/models/concerns/formstrap/validatable.rb +38 -0
- data/app/models/concerns/formstrap/wrappable.rb +19 -0
- data/app/models/formstrap/.DS_Store +0 -0
- data/app/models/formstrap/association_view.rb +100 -0
- data/app/models/formstrap/blocks_view.rb +43 -0
- data/app/models/formstrap/checkbox_view.rb +50 -0
- data/app/models/formstrap/color_view.rb +45 -0
- data/app/models/formstrap/date_range_view.rb +23 -0
- data/app/models/formstrap/date_view.rb +43 -0
- data/app/models/formstrap/datetime_range_view.rb +23 -0
- data/app/models/formstrap/datetime_view.rb +43 -0
- data/app/models/formstrap/email_view.rb +46 -0
- data/app/models/formstrap/file_view.rb +106 -0
- data/app/models/formstrap/flatpickr_range_view.rb +89 -0
- data/app/models/formstrap/flatpickr_view.rb +27 -0
- data/app/models/formstrap/hidden_view.rb +8 -0
- data/app/models/formstrap/hint_view.rb +4 -0
- data/app/models/formstrap/input_group_view.rb +17 -0
- data/app/models/formstrap/label_view.rb +22 -0
- data/app/models/formstrap/media_item_view.rb +41 -0
- data/app/models/formstrap/media_view.rb +143 -0
- data/app/models/formstrap/number_view.rb +47 -0
- data/app/models/formstrap/password_view.rb +42 -0
- data/app/models/formstrap/redactorx_view.rb +57 -0
- data/app/models/formstrap/search_view.rb +46 -0
- data/app/models/formstrap/select_view.rb +61 -0
- data/app/models/formstrap/switch_view.rb +21 -0
- data/app/models/formstrap/text_view.rb +46 -0
- data/app/models/formstrap/textarea_view.rb +47 -0
- data/app/models/formstrap/url_view.rb +46 -0
- data/app/models/formstrap/wrapper_view.rb +17 -0
- data/app/models/formstrap/wysiwyg_view.rb +15 -0
- data/app/models/view_model.rb +62 -0
- data/app/views/formstrap/_association.html.erb +30 -0
- data/app/views/formstrap/_autocomplete.html.erb +11 -0
- data/app/views/formstrap/_blocks.html.erb +45 -0
- data/app/views/formstrap/_checkbox.html.erb +34 -0
- data/app/views/formstrap/_color.html.erb +32 -0
- data/app/views/formstrap/_datalist.html.erb +3 -0
- data/app/views/formstrap/_date.html.erb +41 -0
- data/app/views/formstrap/_date_range.html.erb +40 -0
- data/app/views/formstrap/_datetime.html.erb +41 -0
- data/app/views/formstrap/_datetime_range.html.erb +40 -0
- data/app/views/formstrap/_email.html.erb +43 -0
- data/app/views/formstrap/_errors.html.erb +19 -0
- data/app/views/formstrap/_file.html.erb +94 -0
- data/app/views/formstrap/_flatpickr.html.erb +33 -0
- data/app/views/formstrap/_flatpickr_range.html.erb +40 -0
- data/app/views/formstrap/_hidden.html.erb +23 -0
- data/app/views/formstrap/_hint.html.erb +21 -0
- data/app/views/formstrap/_input_group.html.erb +21 -0
- data/app/views/formstrap/_label.html.erb +22 -0
- data/app/views/formstrap/_media.html.erb +60 -0
- data/app/views/formstrap/_number.html.erb +41 -0
- data/app/views/formstrap/_password.html.erb +39 -0
- data/app/views/formstrap/_redactorx.html.erb +31 -0
- data/app/views/formstrap/_repeater.html.erb +128 -0
- data/app/views/formstrap/_search.html.erb +43 -0
- data/app/views/formstrap/_select.html.erb +43 -0
- data/app/views/formstrap/_switch.html.erb +29 -0
- data/app/views/formstrap/_text.html.erb +42 -0
- data/app/views/formstrap/_textarea.html.erb +39 -0
- data/app/views/formstrap/_to_ary.html.erb +0 -0
- data/app/views/formstrap/_url.html.erb +43 -0
- data/app/views/formstrap/_validation.html.erb +18 -0
- data/app/views/formstrap/_wrapper.html.erb +8 -0
- data/app/views/formstrap/_wysiwyg.html.erb +28 -0
- data/app/views/formstrap/autocomplete/_item.html.erb +3 -0
- data/app/views/formstrap/autocomplete/_list.html.erb +3 -0
- data/app/views/formstrap/blocks/_modal.html.erb +20 -0
- data/app/views/formstrap/fields/_base.html.erb +25 -0
- data/app/views/formstrap/fields/_file.html.erb +17 -0
- data/app/views/formstrap/fields/_files.html.erb +17 -0
- data/app/views/formstrap/fields/_group.html.erb +52 -0
- data/app/views/formstrap/fields/_list.html.erb +31 -0
- data/app/views/formstrap/fields/_text.html.erb +17 -0
- data/app/views/formstrap/media/_item.html.erb +38 -0
- data/app/views/formstrap/media/_media_item_modal.html.erb +77 -0
- data/app/views/formstrap/media/_modal.html.erb +40 -0
- data/app/views/formstrap/media/_thumbnail.html.erb +20 -0
- data/app/views/formstrap/media/_validation.html.erb +10 -0
- data/app/views/formstrap/media/create.turbo_stream.erb +5 -0
- data/app/views/formstrap/media/index.html.erb +3 -0
- data/app/views/formstrap/media/index.turbo_stream.erb +11 -0
- data/app/views/formstrap/media/show.html.erb +9 -0
- data/app/views/formstrap/media/thumbnail.html.erb +3 -0
- data/app/views/formstrap/media/update.turbo_stream.erb +3 -0
- data/app/views/formstrap/pagination/_infinite.html.erb +7 -0
- data/app/views/formstrap/repeater/_row.html.erb +53 -0
- data/app/views/formstrap/shared/_notifications.html.erb +20 -0
- data/app/views/formstrap/shared/_popup.html.erb +32 -0
- data/app/views/formstrap/shared/_thumbnail.html.erb +35 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/importmap.rb +2 -0
- data/config/locales/activerecord/en.yml +12 -0
- data/config/locales/activerecord/nl.yml +13 -0
- data/config/locales/defaults/en.yml +215 -0
- data/config/locales/defaults/nl.yml +213 -0
- data/config/locales/devise/en.yml +65 -0
- data/config/locales/devise/nl.yml +85 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/formstrap/forms/en.yml +39 -0
- data/config/locales/formstrap/forms/nl.yml +39 -0
- data/config/locales/formstrap/media/en.yml +24 -0
- data/config/locales/formstrap/media/nl.yml +24 -0
- data/config/locales/formstrap/thumbnail/en.yml +4 -0
- data/config/locales/formstrap/thumbnail/nl.yml +4 -0
- data/config/locales/nl.yml +6 -0
- data/config/routes.rb +11 -0
- data/esbuild-css.js +25 -0
- data/esbuild-js.js +11 -0
- data/formstrap.gemspec +37 -0
- data/formstrap.iml +34 -0
- data/lib/formstrap/engine.rb +27 -0
- data/lib/formstrap/form_builder.rb +177 -0
- data/lib/formstrap/form_helper.rb +19 -0
- data/lib/formstrap/version.rb +3 -0
- data/lib/formstrap.rb +6 -0
- data/package.json +54 -0
- data/src/js/formstrap.js +1 -0
- data/src/scss/formstrap.scss +1 -0
- data/yarn.lock +1998 -0
- metadata +224 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/repeater
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +attribute+ - Name of the attribute of the form model
|
7
|
+
# * +header+ - Name of the template to use as header
|
8
|
+
# * +label+ - Text to show as label. Label will be hidden if value is false
|
9
|
+
# * +templates+ - List of all views that can be used as a template for a new block
|
10
|
+
# * +flush+ - Set to true if you want the list items to sit flush with its parent.
|
11
|
+
# * +row+ - Pass hash with options to pass to the row template.
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
# # Basic version
|
15
|
+
# <% render "formstrap/repeater", form: form, attribute: :questions do |question| %#>
|
16
|
+
# <% render "admin/questions/fields, form: :question" %#>
|
17
|
+
# <% end %#>
|
18
|
+
#
|
19
|
+
# # Let list group sit flush within its container
|
20
|
+
# <% render "formstrap/repeater", form: form, attribute: :questions, flush: true do |question| %#>
|
21
|
+
# <% render "admin/questions/fields, form: :question" %#>
|
22
|
+
# <% end %#>
|
23
|
+
#
|
24
|
+
# # With fixed header row. A header row can be used to show the labels, so you can omit them in the repeated fields
|
25
|
+
# <% render "formstrap/repeater", form: form, attribute: :questions, header: "admin/questions/header" do |question| %#>
|
26
|
+
# <% render "admin/questions/fields, form: :question" %#>
|
27
|
+
# <% end %#>
|
28
|
+
#
|
29
|
+
# # Allow more than one type of fields to be inserted. You must specify the templates as an array of view paths
|
30
|
+
# <% templates = ["admin/questions/fields/type_1", "admin/questions/fields/type_2"] %#>
|
31
|
+
# <% render "formstrap/repeater", form: form, attribute: :questions, templates: templates do |question| %#>
|
32
|
+
# <% render "admin/questions/fields, form: :question" %#>
|
33
|
+
# <% end %#>
|
34
|
+
|
35
|
+
label = local_assigns.has_key?(:label) ? label : nil
|
36
|
+
required = local_assigns.has_key?(:required) ? required : false
|
37
|
+
header = local_assigns.has_key?(:header) ? header : nil
|
38
|
+
templates = local_assigns.has_key?(:templates) ? templates : []
|
39
|
+
flush = local_assigns.has_key?(:flush) ? flush : true
|
40
|
+
row_options = local_assigns.has_key?(:row) ? row : {}
|
41
|
+
|
42
|
+
template_names = templates.map { |template| File.basename(template, ".html.erb") }
|
43
|
+
template_names = template_names.any? ? template_names : ["new"]
|
44
|
+
object_model = form.object.class
|
45
|
+
association_model = object_model.reflect_on_association(attribute).class_name.constantize
|
46
|
+
association_object = association_model.new
|
47
|
+
with_positions = association_object.attributes.keys.include?("position")
|
48
|
+
|
49
|
+
# We sort the collection with ruby to prevent a new query to be made that would dispose of nested object in memory
|
50
|
+
associations = form.object.send(attribute)
|
51
|
+
associations = with_positions ? associations.sort_by{|resource| resource.position} : associations
|
52
|
+
repeater_id = form.object_id
|
53
|
+
pass_thru = template_names.count == 1 ? "[data-template-name=\"#{template_names.first}\"]" : nil
|
54
|
+
show_label = label != false
|
55
|
+
%>
|
56
|
+
|
57
|
+
<!-- Label -->
|
58
|
+
<% if show_label %>
|
59
|
+
<%= render "formstrap/label", form: form, attribute: attribute, text: label, required: required %>
|
60
|
+
<% end %>
|
61
|
+
|
62
|
+
<ul class="repeater list-group <%= "list-group-flush" if flush %> mb-3" data-controller="repeater" data-repeater-target="list" data-repeater-id-value="<%= repeater_id %>">
|
63
|
+
|
64
|
+
<!-- Header -->
|
65
|
+
<% if header %>
|
66
|
+
<li class="list-group-item">
|
67
|
+
<%= render header %>
|
68
|
+
</li>
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
<!-- Rows -->
|
72
|
+
<%= form.fields_for attribute, associations do |ff| %>
|
73
|
+
<%= render "formstrap/repeater/row", row_options.merge(pass_thru: pass_thru, form: ff, repeater_id: repeater_id) do %>
|
74
|
+
<%= yield(ff) %>
|
75
|
+
<% end %>
|
76
|
+
<% end %>
|
77
|
+
|
78
|
+
<!-- Footer -->
|
79
|
+
<li class="list-group-item d-flex justify-content-between align-items-center" data-repeater-target="footer">
|
80
|
+
|
81
|
+
<!-- Empty notice -->
|
82
|
+
<div class="text-secondary invisible" data-repeater-target="empty">
|
83
|
+
<%= t(".empty") %>
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<!-- Button -->
|
87
|
+
<div
|
88
|
+
class="btn btn-sm h-btn-outline-light"
|
89
|
+
data-repeater-target="addButton"
|
90
|
+
data-popup-target="button"
|
91
|
+
data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
|
92
|
+
data-popup-pass-thru="<%= pass_thru %>"
|
93
|
+
data-action="click->repeater#resetButtonIndices click->popup#open"
|
94
|
+
>
|
95
|
+
<%= bootstrap_icon("plus") %>
|
96
|
+
<%= t(".add", name: association_model.model_name.human) %>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<!-- Popup -->
|
100
|
+
<%= render "formstrap/shared/popup", id: "repeater-buttons-#{repeater_id}" do %>
|
101
|
+
<div class="d-grid gap-2">
|
102
|
+
<% template_names.each do |name| %>
|
103
|
+
<div
|
104
|
+
class="btn btn-sm h-btn-outline-light"
|
105
|
+
data-popup-target="button"
|
106
|
+
data-popup-id="<%= "repeater-buttons-#{repeater_id}" %>"
|
107
|
+
data-action="click->repeater#addRow click->popup#close"
|
108
|
+
data-row-index=""
|
109
|
+
data-template-name="<%= name %>"
|
110
|
+
>
|
111
|
+
<%= t("blocks.#{name}", default: name).humanize %>
|
112
|
+
</div>
|
113
|
+
<% end %>
|
114
|
+
</div>
|
115
|
+
<% end %>
|
116
|
+
|
117
|
+
<!-- Templates -->
|
118
|
+
<% template_names.each do |name| %>
|
119
|
+
<template data-repeater-target="template" data-template-name="<%= name %>" data-template-id-regex="<%= association_object.object_id %>">
|
120
|
+
<%= form.fields_for attribute, association_object, child_index: association_object.object_id do |ff| %>
|
121
|
+
<%= render "formstrap/repeater/row", row_options.merge(form: ff, pass_thru: pass_thru, repeater_id: repeater_id) do %>
|
122
|
+
<% yield(ff, name) %>
|
123
|
+
<% end %>
|
124
|
+
<% end %>
|
125
|
+
</template>
|
126
|
+
<% end %>
|
127
|
+
</li>
|
128
|
+
</ul>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/search
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +collection+ - Values to be suggested while typing. Can be an collection array or a remote URL.
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
18
|
+
#
|
19
|
+
# ==== Documentation
|
20
|
+
# https://headmin.dev/docs/forms/search
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/search
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/search_field
|
23
|
+
#
|
24
|
+
# ==== Examples
|
25
|
+
# Basic version
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "formstrap/search", form: form, attribute: "basic_example" %#>
|
28
|
+
# <% end %#>
|
29
|
+
|
30
|
+
search = Formstrap::SearchView.new(local_assigns)
|
31
|
+
%>
|
32
|
+
|
33
|
+
<%= render "formstrap/wrapper", search.wrapper_options do %>
|
34
|
+
<%= render "formstrap/label", search.label_options if search.prepend_label? %>
|
35
|
+
<%= render "formstrap/input_group", search.input_group_options do %>
|
36
|
+
<%= form.search_field(search.attribute, search.input_options) %>
|
37
|
+
<%= render "formstrap/datalist", search.datalist_options if search.datalist? %>
|
38
|
+
<%= render "formstrap/autocomplete", search.autocomplete_options if search.autocomplete? %>
|
39
|
+
<% end %>
|
40
|
+
<%= render "formstrap/validation", search.validation_options if search.validate? %>
|
41
|
+
<%= render "formstrap/hint", search.hint_options if search.hint? %>
|
42
|
+
<%= render "formstrap/label", search.label_options if search.append_label? %>
|
43
|
+
<% end %>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/select
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
# * +collection+ - Values to create option tags for
|
8
|
+
#
|
9
|
+
# ==== Optional parameters
|
10
|
+
# * +append+ - Display as input group with text on the right-hand side
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +tags+ - Allow options to be created dynamically. This will set the multiple attribute to true
|
18
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
19
|
+
#
|
20
|
+
# ==== References
|
21
|
+
# https://headmin.dev/docs/forms/select
|
22
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
|
23
|
+
# https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select
|
24
|
+
#
|
25
|
+
# ==== Examples
|
26
|
+
# Basic version
|
27
|
+
# <%= form_with do |form| %#>
|
28
|
+
# <%= render "formstrap/select", form: form, attribute: :color, collection: %w[red green blue] %#>
|
29
|
+
# <% end %#>
|
30
|
+
|
31
|
+
select = Formstrap::SelectView.new(local_assigns)
|
32
|
+
%>
|
33
|
+
|
34
|
+
<%= render "formstrap/wrapper", select.wrapper_options do %>
|
35
|
+
<%= render "formstrap/label", select.label_options if select.prepend_label? %>
|
36
|
+
<%= render "formstrap/input_group", select.input_group_options do %>
|
37
|
+
<%= form.select(select.attribute, formstrap: false, choices: select.collection, options: select.select_options, html_options: select.input_options) %>
|
38
|
+
<% end %>
|
39
|
+
<%= render "formstrap/validation", select.validation_options if select.validate? %>
|
40
|
+
<%= render "formstrap/hint", select.hint_options if select.hint? %>
|
41
|
+
<%= render "formstrap/datalist", select.datalist_options if select.datalist? %>
|
42
|
+
<%= render "formstrap/label", select.label_options if select.append_label? %>
|
43
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/switch
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +checked_value+ - Value for checked state
|
10
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
11
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
12
|
+
# * +unchecked_value+ - Value for unchecked state
|
13
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
14
|
+
#
|
15
|
+
# ==== References
|
16
|
+
# https://headmin.dev/docs/forms/switch
|
17
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox
|
18
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/check_box
|
19
|
+
#
|
20
|
+
# ==== Examples
|
21
|
+
# Basic version
|
22
|
+
# <%= form_with do |form| %#>
|
23
|
+
# <%= render "formstrap/switch", form: form, attribute: :active %#>
|
24
|
+
# <% end %#>
|
25
|
+
|
26
|
+
switch = Formstrap::SwitchView.new(local_assigns)
|
27
|
+
%>
|
28
|
+
|
29
|
+
<%= render "formstrap/checkbox", switch.options %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/text
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +collection+ - Values to be suggested while typing. Can be an collection array or a remote URL.
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
18
|
+
#
|
19
|
+
# ==== References
|
20
|
+
# https://headmin.dev/docs/forms/text
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/text_field
|
23
|
+
#
|
24
|
+
# ==== Examples
|
25
|
+
# Basic version
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "formstrap/text", form: form, attribute: :title %#>
|
28
|
+
# <% end %#>
|
29
|
+
text = Formstrap::TextView.new(local_assigns)
|
30
|
+
%>
|
31
|
+
|
32
|
+
<%= render "formstrap/wrapper", text.wrapper_options do %>
|
33
|
+
<%= render "formstrap/label", text.label_options if text.prepend_label? %>
|
34
|
+
<%= render "formstrap/input_group", text.input_group_options do %>
|
35
|
+
<%= form.text_field(text.attribute, text.input_options) %>
|
36
|
+
<%= render "formstrap/datalist", text.datalist_options if text.datalist? %>
|
37
|
+
<%= render "formstrap/autocomplete", text.autocomplete_options if text.autocomplete? %>
|
38
|
+
<% end %>
|
39
|
+
<%= render "formstrap/validation", text.validation_options if text.validate? %>
|
40
|
+
<%= render "formstrap/hint", text.hint_options if text.hint? %>
|
41
|
+
<%= render "formstrap/label", text.label_options if text.append_label? %>
|
42
|
+
<% end %>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/textarea
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +float+ - Use floating labels. Defaults to false
|
11
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
12
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
13
|
+
# * +plaintext+ - Render input as plain text.
|
14
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
15
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
16
|
+
#
|
17
|
+
# ==== References
|
18
|
+
# https://headmin.dev/docs/forms/textarea
|
19
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
|
20
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/text_area
|
21
|
+
#
|
22
|
+
# ==== Examples
|
23
|
+
# Basic version
|
24
|
+
# <%= form_with do |form| %#>
|
25
|
+
# <%= render "formstrap/textarea", form: form, attribute: :text %#>
|
26
|
+
# <% end %#>
|
27
|
+
|
28
|
+
textarea = Formstrap::TextareaView.new(local_assigns)
|
29
|
+
%>
|
30
|
+
|
31
|
+
<%= render "formstrap/wrapper", textarea.wrapper_options do %>
|
32
|
+
<%= render "formstrap/label", textarea.label_options if textarea.prepend_label? %>
|
33
|
+
<%= render "formstrap/input_group", textarea.input_group_options do %>
|
34
|
+
<%= form.text_area(textarea.attribute, textarea.input_options) %>
|
35
|
+
<% end %>
|
36
|
+
<%= render "formstrap/validation", textarea.validation_options if textarea.validate? %>
|
37
|
+
<%= render "formstrap/hint", textarea.hint_options if textarea.hint? || textarea.maxlength? %>
|
38
|
+
<%= render "formstrap/label", textarea.label_options if textarea.append_label? %>
|
39
|
+
<% end %>
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/url
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +append+ - Display as input group with text on the right-hand side
|
10
|
+
# * +collection+ - Values to be suggested while typing. Can be an collection array or a remote URL.
|
11
|
+
# * +float+ - Use floating labels. Defaults to false
|
12
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
13
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
14
|
+
# * +list+ - Options are passed through options_for_select
|
15
|
+
# * +plaintext+ - Render input as plain text.
|
16
|
+
# * +prepend+ - Display as input group with text on the left-hand side
|
17
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
18
|
+
#
|
19
|
+
# ==== References
|
20
|
+
# https://headmin.dev/docs/forms/url
|
21
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url
|
22
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/url_field
|
23
|
+
#
|
24
|
+
# ==== Examples
|
25
|
+
# Basic version
|
26
|
+
# <%= form_with do |form| %#>
|
27
|
+
# <%= render "formstrap/url", form: form, attribute: :website_url %#>
|
28
|
+
# <% end %#>
|
29
|
+
|
30
|
+
url = Formstrap::UrlView.new(local_assigns)
|
31
|
+
%>
|
32
|
+
|
33
|
+
<%= render "formstrap/wrapper", url.wrapper_options do %>
|
34
|
+
<%= render "formstrap/label", url.label_options if url.prepend_label? %>
|
35
|
+
<%= render "formstrap/input_group", url.input_group_options do %>
|
36
|
+
<%= form.url_field(url.attribute, url.input_options) %>
|
37
|
+
<%= render "formstrap/datalist", url.datalist_options if url.datalist? %>
|
38
|
+
<%= render "formstrap/autocomplete", url.autocomplete_options if url.autocomplete? %>
|
39
|
+
<% end %>
|
40
|
+
<%= render "formstrap/validation", url.validation_options if url.validate? %>
|
41
|
+
<%= render "formstrap/hint", url.hint_options if url.hint? %>
|
42
|
+
<%= render "formstrap/label", url.label_options if url.append_label? %>
|
43
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/validation
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +id+ - Form object
|
6
|
+
# * +message+ - Name of the attribute of the form model
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +valid+ - Show success message when true, failure message when false (default: true)
|
10
|
+
#
|
11
|
+
# ==== Examples
|
12
|
+
# Basic version
|
13
|
+
# <%= render "formstrap/validation", id: id, message: message %#>
|
14
|
+
%>
|
15
|
+
|
16
|
+
<div class="<%= valid ? "valid-feedback" : "invalid-feedback" %>" id="<%= id %>">
|
17
|
+
<%= message %>
|
18
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%
|
2
|
+
# formstrap/wysiwyg
|
3
|
+
#
|
4
|
+
# ==== Required parameters
|
5
|
+
# * +attribute+ - Name of the attribute of the form model
|
6
|
+
# * +form+ - Form object
|
7
|
+
#
|
8
|
+
# ==== Optional parameters
|
9
|
+
# * +hint+ - Informative text to assist with data input. HTML markup is allowed.
|
10
|
+
# * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
|
11
|
+
# * +toolbar+ - Show toolbar (default true)
|
12
|
+
# * +wrapper+ - Hash with all options for the surrounding html tag
|
13
|
+
#
|
14
|
+
# ==== References
|
15
|
+
# https://headmin.dev/docs/forms/redactorx
|
16
|
+
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
|
17
|
+
# https://apidock.com/rails/ActionView/Helpers/FormHelper/text_area
|
18
|
+
#
|
19
|
+
# ==== Examples
|
20
|
+
# Basic version
|
21
|
+
# <%= form_with do |form| %#>
|
22
|
+
# <%= render "formstrap/redactorx", form: form, attribute: :text %#>
|
23
|
+
# <% end %#>
|
24
|
+
|
25
|
+
wysiwyg = Formstrap::WysiwygView.new(local_assigns)
|
26
|
+
%>
|
27
|
+
|
28
|
+
<%= render "formstrap/redactorx", wysiwyg.options %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div class="modal fade" tabindex="-1" id="modal-block-<%= form.object.id %>">
|
2
|
+
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
3
|
+
<div class="modal-content">
|
4
|
+
<div class="modal-header">
|
5
|
+
<h5 class="modal-title">
|
6
|
+
<%= t(".title", name: name) %>
|
7
|
+
</h5>
|
8
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<%= t(".close") %>"></button>
|
9
|
+
</div>
|
10
|
+
<div class="modal-body">
|
11
|
+
<%= render "formstrap/text", form: form, attribute: :handle %>
|
12
|
+
<%= render "formstrap/checkbox", form: form, attribute: :visible %>
|
13
|
+
</div>
|
14
|
+
<div class="modal-footer">
|
15
|
+
|
16
|
+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><%= t(".close") %></button>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/base
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
# * +field_type+ - Type of the field. Options: [:text, :image, :file, :list, :group]
|
8
|
+
#
|
9
|
+
# ==== Examples
|
10
|
+
# Basic version
|
11
|
+
# <%= render "formstrap/fields/base", form: form, field_type: :text, name: name do |field, label| %#>
|
12
|
+
# <%= render "formstrap/text", form: field, attribute: :value, label: label %#>
|
13
|
+
# <% end %#>
|
14
|
+
field = form.object.fields.detect { |field| field.name.to_s == name.to_s }
|
15
|
+
field = field ? field : form.object.fields.new(field_type: field_type, name: name)
|
16
|
+
label = t("attributes.#{name.to_s.parameterize}", default: field.name.to_s)
|
17
|
+
%>
|
18
|
+
|
19
|
+
<%= form.fields_for :fields, field do |ff| %>
|
20
|
+
<%= ff.hidden_field :id %>
|
21
|
+
<%= ff.hidden_field :name %>
|
22
|
+
<%= ff.hidden_field :field_type %>
|
23
|
+
|
24
|
+
<%= yield ff, label %>
|
25
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/file
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
# Basic version
|
10
|
+
# <%= render "formstrap/fields/file", form: group, name: :file do |field, attribute, label| %#>
|
11
|
+
# <%= render "formstrap/file", form: field, attribute: attribute, label: label %#>
|
12
|
+
# <% end %#>
|
13
|
+
%>
|
14
|
+
|
15
|
+
<%= render "formstrap/fields/base", form: form, field_type: :file, name: name do |field, label| %>
|
16
|
+
<% yield field, :files, label %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/file
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
# Basic version
|
10
|
+
# <%= render "formstrap/fields/file", form: group, name: :file do |field, attribute, label| %#>
|
11
|
+
# <%= render "formstrap/file", form: field, attribute: attribute, label: label %#>
|
12
|
+
# <% end %#>
|
13
|
+
%>
|
14
|
+
|
15
|
+
<%= render "formstrap/fields/base", form: form, field_type: :files, name: name do |field, label| %>
|
16
|
+
<% yield field, :files, label %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/group
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
# * +label+ - Text to show as label. Label will be hidden if value is false
|
8
|
+
# * +named+ - Whether a group has to be wrapped around the passed block. If false, no group will be wrapped around the passed block.
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
# Basic version
|
12
|
+
# <%= render "formstrap/fields/group", form: form, name: :button do |group| %#>
|
13
|
+
# <div class="row">
|
14
|
+
# <div class="col-md-6">
|
15
|
+
# <%= render "formstrap/fields/text", form: group, name: :name do |field, attribute, label| %#>
|
16
|
+
# <%= render "formstrap/text", form: field, attribute: attribute, label: label %#>
|
17
|
+
# <% end %#>
|
18
|
+
# </div>
|
19
|
+
# <div class="col-md-6">
|
20
|
+
# <%= render "formstrap/fields/text", form: group, name: :url do |field, attribute, label| %#>
|
21
|
+
# <%= render "formstrap/text", form: field, attribute: attribute, label: label %#>
|
22
|
+
# <% end %#>
|
23
|
+
# </div>
|
24
|
+
# </div>
|
25
|
+
# <% end %#>
|
26
|
+
|
27
|
+
label = local_assigns.has_key?(:label) ? label : nil
|
28
|
+
wrapper = local_assigns.has_key?(:wrapper) ? local_assigns[:wrapper] : true
|
29
|
+
named = local_assigns.has_key?(:named) ? local_assigns[:named] : true
|
30
|
+
show_label = label != false
|
31
|
+
%>
|
32
|
+
|
33
|
+
<% if named %>
|
34
|
+
<%= render "formstrap/fields/base", form: form, name: name, field_type: :group do |group, field_label| %>
|
35
|
+
<% if show_label %>
|
36
|
+
<%= render "formstrap/label", form: form, attribute: :value, text: label || field_label %>
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<% if wrapper %>
|
40
|
+
<ul class="list-group mb-3">
|
41
|
+
<li class="list-group-item">
|
42
|
+
<%= yield group %>
|
43
|
+
</li>
|
44
|
+
</ul>
|
45
|
+
<% else %>
|
46
|
+
<%= yield group %>
|
47
|
+
<% end %>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
<% else %>
|
51
|
+
<%= yield form %>
|
52
|
+
<% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/list
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
# * +label+ - Text to show as label. Label will be hidden if value is false
|
8
|
+
#
|
9
|
+
# ==== Examples
|
10
|
+
# Basic version
|
11
|
+
# <%= render "formstrap/fields/list", form: form, name: :websites do |list| %#>
|
12
|
+
# <%= render "formstrap/fields/text", form: list, name: :url do |field, attribute, label| %#>
|
13
|
+
# <%= render "formstrap/text", form: field, attribute: attribute, label: label %#>
|
14
|
+
# <% end %#>
|
15
|
+
# <% end %#>
|
16
|
+
|
17
|
+
label = local_assigns.has_key?(:label) ? label : nil
|
18
|
+
show_label = label != false
|
19
|
+
%>
|
20
|
+
|
21
|
+
<%= render "formstrap/fields/base", form: form, name: name, field_type: :list do |list, field_label| %>
|
22
|
+
<div class="mb-3">
|
23
|
+
<%= render "formstrap/repeater", form: list, attribute: :fields, label: show_label ? label || field_label : false, flush: false do |field| %>
|
24
|
+
|
25
|
+
<%= field.hidden_field :field_type, value: :list_item %>
|
26
|
+
<%= field.hidden_field :name, value: :list_item %>
|
27
|
+
|
28
|
+
<%= yield field %>
|
29
|
+
<% end %>
|
30
|
+
</div>
|
31
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%
|
2
|
+
# name: formstrap/fields/text
|
3
|
+
#
|
4
|
+
# ==== Options
|
5
|
+
# * +form+ - Form object
|
6
|
+
# * +name+ - Name for the field
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
# Basic version
|
10
|
+
# <%= render "formstrap/fields/text", form: group, name: :name do |field, attribute, label| %#>
|
11
|
+
# <%= render "formstrap/text", form: field, attribute: attribute, label: label %#>
|
12
|
+
# <% end %#>
|
13
|
+
%>
|
14
|
+
|
15
|
+
<%= render "formstrap/fields/base", form: form, field_type: :text, name: name do |field, label| %>
|
16
|
+
<% yield field, :value, label %>
|
17
|
+
<% end %>
|