Created
February 17, 2019 17:32
-
-
Save deepakmahakale/181b2bdbd156192383e8d3a0d2ba824d to your computer and use it in GitHub Desktop.
Active admin numeric range / number range filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
form.filter_form .filter_form_field.filter_numeric_range input[type='text'] { | |
background-position: 100% 3px; | |
background-repeat: no-repeat; | |
padding-right: 25px; | |
width: calc(50% - 3px); | |
} | |
form.filter_form .filter_form_field.filter_numeric_range .separator, form.filter_form .filter_form_field.filter_numeric_range input[type='text'] { | |
display: inline-block; | |
float: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveAdmin | |
module Inputs | |
module Filters | |
class NumericRangeInput < ::Formtastic::Inputs::StringInput | |
include Base | |
def to_html | |
input_wrapping do | |
[ label_html, | |
builder.text_field(gt_input_name, input_html_options(gt_input_name, gt_input_placeholder)), | |
builder.text_field(lt_input_name, input_html_options(lt_input_name, lt_input_placeholder)), | |
].join("\n").html_safe | |
end | |
end | |
def gt_input_name | |
"#{method}_gteq" | |
end | |
alias :input_name :gt_input_name | |
def lt_input_name | |
"#{method}_lteq" | |
end | |
def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeholder) | |
current_value = @object.public_send(input_name) | |
{ size: 12, placeholder: placeholder, value: current_value } | |
end | |
def gt_input_placeholder | |
I18n.t('active_admin.filters.predicates.from') | |
end | |
def lt_input_placeholder | |
I18n.t('active_admin.filters.predicates.to') | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment