module DefaultForm::Builder::Helper
Constants
- INPUT_FIELDS
Public Instance Methods
check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 50 def check_box(method, options = {}, checked_value = '1', unchecked_value = '0') wrap_all_with(method, options) do |css| default_options(method, options) options[:class] = css.dig(:origin, :checkbox) unless options.key?(:class) r = options.delete(:label) if r.present? label_text = content_tag(:span, r) else label_text = '' end checkbox_content = wrapping(:checkbox, super + label_text, wrap: css[:wrap], tag: 'label') offset(css.dig(:offset, :submit)) + checkbox_content end end
collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 66 def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) wrap_with(method, options) do |css| wrapping(:checkboxes, super, wrap: css[:wrap]) end end
collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 100 def collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) wrap_with(method, options) do |css| html_options[:class] = if html_options[:multiple] css.dig(:origin, :multi_select) else css.dig(:origin, :select) end unless html_options.key?(:class) options[:include_blank] = I18n.t('helpers.select.prompt') if options[:include_blank] == true wrapping(:select, super, wrap: css[:wrap]) end end
date_field(method, options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 137 def date_field(method, options = {}) wrap_with(method, options) do |css| options[:class] = css.dig(:origin, :input) unless options.key?(:class) if method.end_with?('(date)') real_method = method.to_s.sub('(date)', '') options[:data] = {} options[:data].merge! controller: 'datetime', action: 'datetime#default' if object.column_for_attribute(real_method).type == :datetime options[:value] = object.read_attribute(real_method)&.to_date end wrapping(:input, super, wrap: css[:wrap]) end end
fields(scope = nil, model: nil, **options, &block)
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 27 def fields(scope = nil, model: nil, **options, &block) options[:theme] ||= theme super end
label(method, text = nil, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 32 def label(method, text = nil, options = {}, &block) origin = (options.delete(:origin) || {}).with_defaults!(origin_css) wrap = (options.delete(:wrap) || {}).with_defaults!(wrap_css) options[:class] = origin[:label] unless options.key?(:class) wrapping(:label, super, wrap: wrap) end
number_field(method, options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 151 def number_field(method, options = {}) wrap_with(method, options) do |css| options[:class] = css.dig(:origin, :input) unless options.key?(:class) options[:step] = default_step(method) unless options.key?(:step) wrapping(:input, super, wrap: css[:wrap]) end end
select(method, choices = nil, options = {}, html_options = {}, &block)
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 86 def select(method, choices = nil, options = {}, html_options = {}, &block) wrap_with(method, options) do |css| options[:selected] ||= default_value(method) if html_options[:multiple] html_options[:class] = css.dig(:origin, :multi_select) else html_options[:class] = css.dig(:origin, :select) end unless html_options.key?(:class) options[:include_blank] = I18n.t('helpers.select.prompt') if options[:include_blank] == true wrapping(:select, super, wrap: css[:wrap]) end end
submit(value = nil, options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 40 def submit(value = nil, options = {}) wrap_all_with(nil, options) do |css| options[:class] = css.dig(:origin, :submit) unless options.key?(:class) css[:wrap][:all] = css.dig(:wrap, :all_submit) submit_content = wrapping(:submit, super, wrap: css[:wrap]) offset(css.dig(:offset, :submit)) + submit_content end end
text_area(method, options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 159 def text_area(method, options = {}) wrap_with(method, options) do |css| options[:class] = css.dig(:origin, :textarea) unless options.key?(:class) wrapping(:input, super, wrap: css[:wrap]) end end
time_select(method, options = {}, html_options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 125 def time_select(method, options = {}, html_options = {}) wrap_with(method, options) do |css| html_options[:class] = css.dig(:origin, :select) unless html_options.key?(:class) wrapping(:select, super, wrap: css[:wrap]) end end
time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
click to toggle source
Calls superclass method
# File lib/default_form/builder/helper.rb, line 113 def time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) wrap_with(method, options) do |css| html_options[:class] = if html_options[:multiple] css.dig(:origin, :multi_select) else css.dig(:origin, :select) end unless html_options.key?(:class) wrapping(:select, super, wrap: css[:wrap]) end end
wrap_all_with(method, options) { |css| ... }
click to toggle source
block 应返回 label_content + input_content 的内容
# File lib/default_form/builder/helper.rb, line 183 def wrap_all_with(method, options) css = {} css[:origin] = origin_css.merge options.delete(:origin) || {} css[:wrap] = wrap_css.merge options.delete(:wrap) || {} css[:error] = error_css.merge options.delete(:error) || {} css[:offset] = offset_css.merge options.delete(:offset) || {} inner_content = yield css wrapping_all inner_content, method, wrap: css[:wrap], required: options[:required] end
wrap_with(method, options = {}) { |css| ... }
click to toggle source
block 应返回 input with wrapper 的内容
# File lib/default_form/builder/helper.rb, line 167 def wrap_with(method, options = {}) wrap_all_with(method, options) do |css| default_options(method, options) if options[:label] label_content = label method, options.delete(:label), options.slice(:origin, :wrap) else options.delete(:label) label_content = ''.html_safe end input_content = yield css label_content + input_content end end