Question

VIEW FILE

<%= javascript_include_tag "calender" %>
<%= simple_form_for(@obj, :html => {:class => 'form-vertical'}) do |f| %>
<%= f.input :created_at, :as=> 'datepicker' ,:label => 'Date of send' %>
<%end%>

CALENDER.JS

$(document).ready(function(){
$('input.datepicker').datepicker();
});

When running ...getting error like

No input found for datepicker

when i remove . :as => 'datepicker' though calender doesnt come but it does not show error also. Kindly let me know whether I am doing correctly ?

Was it helpful?

Solution

replace this: <%= f.input :created_at, :as=> 'datepicker' ,:label => 'Date of send' %>

with:

<%= f.input :created_at, :as=> 'string' ,:label => 'Date of send', input_html: { class: 'datepicker' } %>


explanation:

f.input :created_at, :as=> 'datepicker'.. doesn't work because simple_form gem doesn't know about input of type :datepicker. And because the actual datepicker js library is designed to work with input type="text" you should just tell simple_form to use this kind of input with as: 'string'. Then the js library does it's part and transforms standart text input into a datepicker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top