Sha256: 992d40deca0e6e7bf6c9205448e6e8acbc50d55608442992b75dfddfc8cf3f6e
Contents?: true
Size: 1.98 KB
Versions: 3
Compression:
Stored size: 1.98 KB
Contents
class Shadcn::FormBuilder < ActionView::Helpers::FormBuilder def label(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_label(name: "#{object_name}[#{method}]", label: label_for(@object, method), **options) end def text_field(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_input( name: "#{object_name}[#{method}]", id: "#{object_name}_#{method}", value: @object.send(method), type: "text", **options ) end def password_field(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_input( name: "#{object_name}[#{method}]", id: "#{object_name}_#{method}", value: @object.send(method), type: "password", **options ) end def email_field(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_input( name: "#{object_name}[#{method}]", id: "#{object_name}_#{method}", value: @object.send(method), type: "email", **options ) end def text_area(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_textarea( name: "#{object_name}[#{method}]", id: "#{object_name}_#{method}", value: @object.send(method), type: "text", **options ) end def submit(value = nil, options = {}) @template.render_button(value, **options) end private def label_for(object, method) return method.capitalize if object.nil? object.class.human_attribute_name(method) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
shadcn-ui-0.0.15 | app/components/shadcn/form_builder.rb |
shadcn-ui-0.0.14 | app/components/shadcn/form_builder.rb |
shadcn-ui-0.0.13 | app/components/shadcn/form_builder.rb |