Closed Beartech closed 11 years ago
Can you show me the input's code?
<%= form_for(@tool) do |f| %>
<% if @tool.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tool.errors.count, "error") %> prohibited this tool from being saved:</h2>
<ul>
<% @tool.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :serial %><br>
<%= f.text_field :serial %>
</div>
<div class="field">
<%= f.label :location %><br>
<%= f.text_field :location %>
</div>
<div class="field" >
<%= f.label :purchased %><br>
<%= f.text_field :purchased, 'data-behaviour' => 'datepicker' %>
</div>
<div class="field" >
<%= f.label :put_in_service %><br>
<%= f.text_field :put_in_service, 'data-behaviour' => 'datepicker' %>
</div>
<div class="field">
<%= f.label :cost %><br>
<%= f.text_field :cost %>
</div>
<div class="field">
<%= f.label :value %><br>
<%= f.text_field :value %>
</div>
<div class="field">
<%= f.label :in_service %><br>
<%= f.check_box :in_service %>
</div>
<div class="field" >
<%= f.label :retired %><br>
<%= f.text_field :retired, 'data-behaviour' => 'datepicker' %>
</div>
<div class="field">
<%= f.label :condition %><br>
<%= f.select(:condition, [['5',5],['4',4],['3',3],['2',2],['1',1]] ) %>
</div>
<div class="field">
<%= f.label :note %><br>
<%= f.text_area :note %>
</div>
<%= f.submit %>
<% end %>
Try with:
$('[data-behaviour~=datepicker]').datepicker(
{"format": "mm-dd-yyyy", "weekStart": 1, "autoclose": true});
I just updated the gem. The last version of this gem should have the same code as that repo. Do you still have this issue?
I have been using a different date picker that I found online. If I get a chance I will try this one to see if it works with my app.
Andy
On Sun, Jul 21, 2013 at 1:29 PM, Paul Keister notifications@github.comwrote:
Actually I'm not using the gem - I came across this issue report when I was doing research on this problem, which appears to be the same reported by @Beartech https://github.com/Beartech. I can do an A/B test to make sure this repo also has the fix, but not until Monday at the earliest. FYI I'm on ASP.NET MVC, so I still won't be using the gem.
— Reply to this email directly or view it on GitHubhttps://github.com/Nerian/bootstrap-datepicker-rails/issues/57#issuecomment-21316419 .
I branched my project, removed all of the other date picker code I had, then added this to my gem file and ran bundle install. I added the lines to application.css.scss and application.js as recommended on this repo's main page. I then ran 'rake assets:clean' and 'RAILS_ENV=production bundle exec rake assets:precompile'. I started the rails server and opened my app in Safari. Now I get no date picker at all. I tried in Chrome with same result, no date picker at all. :-(
my HTML is:
my compiled Javascript file looks like:
$('[data-behaviour~=datepicker]').datepicker( {"format": "mm-dd-yyyy", "weekStart": 1, "autoclose": true});
I am horrible with javascript. No clue what I'm doing wrong.
Sorry, didn't escape that html as code block, here it is:
<label for="tool_purchased">Purchased</label>
<input data-behaviour="datepicker" id="tool_purchased" name="tool[purchased]" type="text">
Do you have your js code inside a ready
event? Like:
$(document).on('ready', function(){
$('[data-behaviour~=datepicker]').datepicker({"format": "mm-dd-yyyy", "weekStart": 1, "autoclose": true});
});
Ah, no. I just removed that branch and rolled back to my old code. Let me clone my app and try that.
Check the Chrome javascript console for errors too.
There is also a TestApp that you can check. It contains the minimum that is necessary:
https://github.com/Nerian/bootstrap-datepicker-rails/tree/master/testapp
Success! I cloned my app, removed the old date-picker, added yours with the above code and it appears to be working perfect.
I am using Rails 4.0 & Ruby 2.0 with Twitter-Bootstrap-Rails. Datepicker works great, except if I edit a record and click on the date ( or create a new record) I can't click away from the date without it putting in a date. If I click into the field and delete the date, when I click away it still fills it back in with today's date. I'm new enough to not be able to tell if this is something I am doing wrong or a bug. My JS code is:
If I clear out the date and click away from the text input field it automatically inserts today's day.