lib/alchemy/forms/builder.rb in alchemy_cms-6.0.0.b1 vs lib/alchemy/forms/builder.rb in alchemy_cms-6.0.0.b2

- old
+ new

@@ -16,14 +16,34 @@ end super end + # Renders a simple_form input that displays a datepicker + # + def datepicker(attribute_name, options = {}) + options[:wrapper] = :alchemy + + type = options[:as] || :date + value = options.fetch(:input_html, {}).delete(:value) + date = value || object.send(attribute_name.to_sym).presence + date = Time.zone.parse(date) if date.is_a?(String) + + input_options = { + type: :text, + class: type, + data: { datepicker_type: type }, + value: date&.iso8601, + }.merge(options[:input_html] || {}) + + input attribute_name, as: :string, input_html: input_options + end + # Renders a button tag wrapped in a div with 'submit' class. # def submit(label, options = {}) options = { - wrapper_html: {class: "submit"}, + wrapper_html: { class: "submit" }, }.update(options) template.content_tag("div", options.delete(:wrapper_html)) do template.content_tag("button", label, options.delete(:input_html)) end end