Created
March 11, 2015 15:39
-
-
Save sakirtemel/3d86fd3310455eb313b9 to your computer and use it in GitHub Desktop.
Simple form date picker input
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
# Use f.input :start_date, as: :date_picker | |
class DatePickerInput < SimpleForm::Inputs::Base | |
def input(wrapper_options = nil) | |
input_html_classes.delete(:date_picker) | |
input_html_classes << :string | |
input_html_classes << 'datepicker' | |
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) | |
text_field = @builder.text_field(attribute_name, merged_input_options) | |
hidden_field = @builder.hidden_field(attribute_name, {:id => tag_id(@builder, attribute_name) + "_alt"}) | |
text_field + hidden_field | |
end | |
private | |
def tag_id(builder, attribute_name) | |
"#{sanitized_object_name(builder.object_name)}_#{sanitized_method_name(attribute_name.to_s)}" | |
end | |
def sanitized_object_name(object_name) | |
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") | |
end | |
def sanitized_method_name(method_name) | |
method_name.sub(/\?$/, "") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment