Module: Datagrid::FormBuilder
- Defined in:
- lib/datagrid/form_builder.rb
Instance Method Summary collapse
-
#datagrid_filter(filter_or_attribute, **options, &block) ⇒ String
A form input html for the corresponding filter name * select for enum, xboolean filter types * check_box for boolean filter type * text_field for other filter types.
-
#datagrid_filter_input(attribute_or_filter, **options, &block) ⇒ String
An input tag for the corresponding filter name.
-
#datagrid_label(filter_or_attribute, text = nil, **options, &block) ⇒ String
A form label tag for the corresponding filter name.
Instance Method Details
#datagrid_filter(filter_or_attribute, **options, &block) ⇒ String
Returns a form input html for the corresponding filter name
- select for enum, xboolean filter types
- check_box for boolean filter type
- text_field for other filter types.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/datagrid/form_builder.rb', line 14 def datagrid_filter(filter_or_attribute, **, &block) filter = datagrid_get_filter(filter_or_attribute) if filter.range? datagrid_range_filter(filter, , &block) elsif filter.enum_checkboxes? datagrid_enum_checkboxes_filter(filter, , &block) elsif filter.type == :dynamic datagrid_dynamic_filter(filter, , &block) else datagrid_filter_input(filter, **, &block) end end |
#datagrid_filter_input(attribute_or_filter, **options, &block) ⇒ String
Returns an input tag for the corresponding filter name.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/datagrid/form_builder.rb', line 42 def datagrid_filter_input(attribute_or_filter, **, &block) filter = datagrid_get_filter(attribute_or_filter) = (filter, **) type = .delete(:type)&.to_sym if %i[datetime-local date].include?(type) if .key?(:value) && [:value].nil? # https://github.com/rails/rails/pull/53387 [:value] = "" end elsif [:value] [:value] = filter.format([:value]) end case type when :"datetime-local" datetime_local_field filter.name, **, &block when :date date_field filter.name, **, &block when :textarea text_area filter.name, value: object.filter_value_as_string(filter), **, &block when :checkbox value = .fetch(:value, 1).to_s = { checked: true, ** } if filter.enum_checkboxes? && enum_checkbox_checked?(filter, value) check_box filter.name, , value when :hidden hidden_field filter.name, ** when :number number_field filter.name, ** when :select select( filter.name, object.(filter) || [], { include_blank: filter.include_blank, prompt: filter.prompt, include_hidden: false, }, multiple: filter.multiple?, **, &block ) else text_field filter.name, value: object.filter_value_as_string(filter), **, &block end end |
#datagrid_label(filter_or_attribute, text = nil, **options, &block) ⇒ String
Returns a form label tag for the corresponding filter name.
31 32 33 34 35 |
# File 'lib/datagrid/form_builder.rb', line 31 def datagrid_label(filter_or_attribute, text = nil, **, &block) filter = datagrid_get_filter(filter_or_attribute) = { **filter., ** } label(filter.name, text || filter.header, **, &block) end |