Skip to content

Instantly share code, notes, and snippets.

@sebastyuiop
Created January 25, 2013 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastyuiop/4631606 to your computer and use it in GitHub Desktop.
Save sebastyuiop/4631606 to your computer and use it in GitHub Desktop.
SimpleForm input that provides for example f.input :foo, :as => :time_picker
class TimePickerInput < SimpleForm::Inputs::Base
def input
js_node_id = input_html_options[:id] || "#{object_name}_#{attribute_name}"
template.content_tag :div, :class => 'input-append time' do
@builder.text_field(attribute_name, input_html_options.merge(:class => 'input-medium')) +
template.content_tag(:span, :class => 'add-on') do
template.content_tag :i, '', :class => 'icon-time'
end + js_code(js_node_id).html_safe
end
end
def js_code(node_id)
<<-eos
<script type="text/javascript">
$(function() {
$("##{node_id}").timepicker();
});
</script>
eos
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment