Reputation: 1
I've been struggling to get the bootstrap-datepicker to work in my rails application. Any help would be appreciated. Thanks!!
Rails -v: 3.2.12 jquery-rails: 3.0.4, 3.0.2, ....
Here is the js in my html file:
<link href="/assets/datepicker.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-transition.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-affix.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-alert.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-button.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-carousel.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-collapse.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-scrollspy.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tab.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tooltip.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-typeahead.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-datepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
html snippet:
<div class="control-group">
<label class="control-label" for="vps_eta_date">Estimated arrival date</label>
<div class="controls">
<div class="input-append date" id="dp3" data-date-format="dd-mm-yyyy">
<input class="span2" size="16" id="vps_eta_date" name="vps[eta_date]" type="text" value="12-02-2013" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
</div>
html file also include the following script copied this from an example (http://vitalets.github.io/bootstrap-datepicker/):
<script>
$(function(){
window.prettyPrint && prettyPrint();
$('#dp1').datepicker({
format: 'mm-dd-yyyy',
todayBtn: 'linked'
});
$('#dp2').datepicker();
$('#btn2').click(function(e){
e.stopPropagation();
$('#dp2').datepicker('update', '03/17/12');
});
$('#dp3').datepicker();
var startDate = new Date(2012,1,20);
var endDate = new Date(2012,1,25);
$('#dp4').datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() > endDate.valueOf()){
$('#alert').show().find('strong').text('The start date can not be greater then the end date');
} else {
$('#alert').hide();
startDate = new Date(ev.date);
$('#startDate').text($('#dp4').data('date'));
}
$('#dp4').datepicker('hide');
});
$('#dp5').datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() < startDate.valueOf()){
$('#alert').show().find('strong').text('The end date can not be less then the start date');
} else {
$('#alert').hide();
endDate = new Date(ev.date);
$('#endDate').text($('#dp5').data('date'));
}
$('#dp5').datepicker('hide');
});
//inline
$('#dp6').datepicker({
todayBtn: 'linked'
});
$('#btn6').click(function(){
$('#dp6').datepicker('update', '15-05-1984');
});
$('#btn7').click(function(){
$('#dp6').data('datepicker').date = null;
$('#dp6').find('.active').removeClass('active');
});
});
</script>
Upvotes: 0
Views: 2179
Reputation: 1
I have directly included the following in my section:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
I used the before mentioned form and javascript snippent. jquery-ui's datpicker is working for me now and I will continue with this solution and revisit this later.
Thanks for you help, but there is something screwy with the both the bootstrap-datepicker-rails and jquery-ui-rails gems and how they interact with all the other javascript files.
Upvotes: 0
Reputation: 8220
You can use bootstrap-datepicker-rails gem, I suggestion for using it.
Put bootstrap-datepicker-rails
into your Gemfile;
gem 'bootstrap-datepicker-rails'
And run bundle, then Add this line to app/assets/stylesheets/application.css
*= require bootstrap-datepicker
Add this line to app/assets/javascripts/application.js
//= require bootstrap-datepicker
And on views (e.g form)
<%= f.text_field :mydate, 'data-behaviour' => 'datepicker' %>
<script type="text/javascript">
$('[data-behaviour~=datepicker]').datepicker();
</script>
Or As component :
<div class="input-append date datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
<%= f.text_field :mydate, 'data-behaviour' => 'datepicker', :disabled => 'disable' %><span class="add-on"><i class="icon-th"></i></span>
</div>
<script type="text/javascript">
$('.datepicker').datepicker();
</script>
Upvotes: 1