Class: PandaCms::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/builders/panda_cms/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#button(value = nil, options = {}, &block) ⇒ Object

> 7.1.3



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/builders/panda_cms/form_builder.rb', line 73

def button(value = nil, options = {}, &block) # => 7.1.3
  case value
  when Hash
    value, options = nil, value
  when Symbol
    value, options = nil, {name: field_name(value), id: field_id(value)}.merge!(options.to_h)
  end
  value ||= submit_default_value

  formmethod = options[:formmethod]
  if formmethod.present? && !/post|get/i.match?(formmethod) && !options.key?(:name) && !options.key?(:value)
    options.merge! formmethod: :post, name: "_method", value: formmethod
  end

  value = if block
    @template.capture { yield(value) }
  else
    (:i, "", class: "fa-sharp fa-circle-check mr-1 pt-[0.2rem]") + value
  end

  @template.button_tag(value, options.reverse_merge(class: button_styles))
end

#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



100
101
102
103
104
# File 'app/builders/panda_cms/form_builder.rb', line 100

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: "border-gray-300 ml-2"), checked_value, unchecked_value)
  end
end

#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



55
56
57
58
59
# File 'app/builders/panda_cms/form_builder.rb', line 55

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, collection, value_method, text_method, options, html_options.reverse_merge(class: input_styles))
  end
end

#date_field(method, options = {}) ⇒ Object



106
107
108
109
110
# File 'app/builders/panda_cms/form_builder.rb', line 106

def date_field(method, options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: input_styles))
  end
end

#datetime_field(attribute, options = {}) ⇒ Object



31
32
33
34
35
# File 'app/builders/panda_cms/form_builder.rb', line 31

def datetime_field(attribute, options = {})
   :div, class: container_styles do
    label(attribute) + meta_text(options) + super(attribute, options.reverse_merge(class: input_styles))
  end
end

#email_field(attribute, options = {}) ⇒ Object



25
26
27
28
29
# File 'app/builders/panda_cms/form_builder.rb', line 25

def email_field(attribute, options = {})
   :div, class: container_styles do
    label(attribute) + meta_text(options) + super(attribute, options.reverse_merge(class: input_styles))
  end
end

#file_field(method, options = {}) ⇒ Object



67
68
69
70
71
# File 'app/builders/panda_cms/form_builder.rb', line 67

def file_field(method, options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: "file:rounded file:border-0 file:text-sm file:bg-white file:text-gray-500 hover:file:bg-gray-50 bg-white px-2.5 hover:bg-gray-50".concat(input_styles)))
  end
end

#label(attribute, text = nil, options = {}, &block) ⇒ Object



5
6
7
# File 'app/builders/panda_cms/form_builder.rb', line 5

def label(attribute, text = nil, options = {}, &block)
  super(attribute, text, options.reverse_merge(class: label_styles))
end

#meta_text(options) ⇒ Object



124
125
126
127
128
# File 'app/builders/panda_cms/form_builder.rb', line 124

def meta_text(options)
  if options[:meta]
     :span, options[:meta], class: "block text-black/60 italic text-sm mb-2"
  end
end

#password_field(attribute, options = {}) ⇒ Object



43
44
45
46
47
# File 'app/builders/panda_cms/form_builder.rb', line 43

def password_field(attribute, options = {})
   :div, class: container_styles do
    label(attribute) + meta_text(options) + super(attribute, options.reverse_merge(class: input_styles))
  end
end

#rich_text_area(method, options = {}) ⇒ Object



112
113
114
115
116
# File 'app/builders/panda_cms/form_builder.rb', line 112

def rich_text_area(method, options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: textarea_styles))
  end
end

#rich_text_field(method, options = {}) ⇒ Object



118
119
120
121
122
# File 'app/builders/panda_cms/form_builder.rb', line 118

def rich_text_field(method, options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: textarea_styles))
  end
end

#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object



49
50
51
52
53
# File 'app/builders/panda_cms/form_builder.rb', line 49

def select(method, choices = nil, options = {}, html_options = {}, &block)
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, choices, options, html_options.reverse_merge(class: input_styles))
  end
end

#submit(value = nil, options = {}) ⇒ Object

> 7.1.3



96
97
98
# File 'app/builders/panda_cms/form_builder.rb', line 96

def submit(value = nil, options = {}) # => 7.1.3
  super(value, options.reverse_merge(class: button_styles))
end

#text_area(method, options = {}) ⇒ Object



37
38
39
40
41
# File 'app/builders/panda_cms/form_builder.rb', line 37

def text_area(method, options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, options.reverse_merge(class: input_styles))
  end
end

#text_field(attribute, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/builders/panda_cms/form_builder.rb', line 9

def text_field(attribute, options = {})
  if options.dig(:data, :prefix)
     :div, class: container_styles do
      label(attribute) + meta_text(options) +
        (:div, class: "flex flex-grow") do
          (:span, class: "inline-flex items-center px-3 text-base border border-r-none rounded-s-md whitespace-nowrap break-keep") { options.dig(:data, :prefix) } +
            super(attribute, options.reverse_merge(class: input_styles_prefix + " input-prefix rounded-l-none border-l-none"))
        end
    end
  else
     :div, class: container_styles do
      label(attribute) + meta_text(options) + super(attribute, options.reverse_merge(class: input_styles))
    end
  end
end

#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object



61
62
63
64
65
# File 'app/builders/panda_cms/form_builder.rb', line 61

def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
   :div, class: container_styles do
    label(method) + meta_text(options) + super(method, priority_zones, options, html_options.reverse_merge(class: input_styles))
  end
end