Class: Alchemy::Forms::Builder
- Inherits:
-
SimpleForm::FormBuilder
- Object
- SimpleForm::FormBuilder
- Alchemy::Forms::Builder
- Defined in:
- lib/alchemy/forms/builder.rb
Instance Method Summary collapse
-
#datepicker(attribute_name, options = {}) ⇒ Object
Renders a simple_form input that displays a datepicker.
-
#input(attribute_name, options = {}, &block) ⇒ Object
Renders a simple_form input, but uses input alchemy_wrapper.
-
#richtext(attribute_name, options = {}) ⇒ Object
Renders a simple_form input that displays a richtext editor.
-
#submit(label, options = {}) ⇒ Object
Renders a button tag wrapped in a div with ‘submit’ class.
Instance Method Details
#datepicker(attribute_name, options = {}) ⇒ Object
Renders a simple_form input that displays a datepicker
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/alchemy/forms/builder.rb', line 30 def datepicker(attribute_name, = {}) type = [:as] || :date value = .fetch(:input_html, {}).delete(:value) date = value || object.send(attribute_name.to_sym).presence date = Time.zone.parse(date) if date.is_a?(String) = { type: :text, class: type, value: date&.iso8601 }.merge([:input_html] || {}) date_field = input attribute_name, as: :string, input_html: template.content_tag("alchemy-datepicker", date_field, "input-type" => type) end |
#input(attribute_name, options = {}, &block) ⇒ Object
Renders a simple_form input, but uses input alchemy_wrapper
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/alchemy/forms/builder.rb', line 8 def input(attribute_name, = {}, &block) [:wrapper] = :alchemy if object.respond_to?(:attribute_fixed?) && object.attribute_fixed?(attribute_name) = { content: Alchemy.t(:attribute_fixed, attribute: attribute_name), class: "like-hint-tooltip", placement: "bottom-start" } template.content_tag(:div, class: "input") do label(attribute_name) + template.content_tag("sl-tooltip", ) do input_field(attribute_name, disabled: true) end end else super end end |
#richtext(attribute_name, options = {}) ⇒ Object
Renders a simple_form input that displays a richtext editor
48 49 50 51 |
# File 'lib/alchemy/forms/builder.rb', line 48 def richtext(attribute_name, = {}) text_area = input(attribute_name, .merge(as: :text)) template.content_tag("alchemy-tinymce", text_area) end |
#submit(label, options = {}) ⇒ Object
Renders a button tag wrapped in a div with ‘submit’ class.
55 56 57 58 59 60 61 62 63 |
# File 'lib/alchemy/forms/builder.rb', line 55 def submit(label, = {}) = { wrapper_html: {class: "submit"}, input_html: {is: "alchemy-button"} }.update() template.content_tag("div", .delete(:wrapper_html)) do template.(label, .delete(:input_html)) end end |