stop bootstrap date-picker selecting today date - ruby-on-rails

I've got a bootstrap date picker on my ruby on rails application but it keeps selecting today date as default how do I stop this?
Javascript
<script type="text/javascript">
$(".datepicker").attr('readOnly', 'true').css("background-color","white");
$(document).ready(function(){
$('.datepicker').datepicker({
"setDate": new Date(-70),
yearRange : '-70:-19',
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
autoclose: true});
});
</script>
As shown below today's date 30th march is selected. If the user doesn't change the year or month all dates for march in initial view will select for
"day March 2018"
Any help is much appreciated!

First of all, this is not a bootstrap datePicker this is jquery datePicker, see the below for bootstrap datePicker, for bootstrap datePicker you can use bootstrap datePicker gem, try to the following added to todayHighlight: false
$(document).ready(function() {
var dateInput = $('input[name="date"]'); // Our date input has the name "date"
var container = $('.bootstrap-iso form').length > 0 ? $('.bootstrap-iso form').parent() : 'body';
dateInput.datepicker({
"setDate": new Date(-70),
yearRange : '-70:-19',
dateFormat: 'dd/mm/yy',
todayHighlight: false,
changeMonth: true,
changeYear: true,
autoclose: true
});
$('#date').datepicker('setStartDate'); // <-- SO DOES THIS
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/css/tether.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.min.css" rel="stylesheet"/>
<div class="bootstrap-iso">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<form class="form-horizontal" method="post">
<div class="form-group ">
<div class="col-sm-10">
<input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>

Related

Restricting uib-datepicker to just one year

How do I fix the uib-datepicker to just one year. (say current year only).
I tried searching but all that I could find was to restrict calendar to year mode only. I tried setting year:2016 in datepicker-options but it didn't work.
Any suggestions ???
You can to use minDate and maxDate properties in the datepicker-options object as described in the docs.
The following code shows a datepicker limited to the current year:
angular.module('MyApp',['ui.bootstrap']).controller('AppCtrl', function($scope) {
$scope.open1 = function() {
$scope.popup1.opened = true;
};
$scope.dateOptions = {
minDate: moment().startOf('year').toDate(),
maxDate: moment().endOf('year').toDate()
};
$scope.format = 'dd-MMMM-yyyy';
$scope.popup1 = {
opened: false
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-animate.min.js "></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-touch.min.js "></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.2.0/ui-bootstrap-tpls.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<div ng-app="MyApp" ng-controller="AppCtrl">
<div class="row">
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" datepicker-options="dateOptions" show-button-bar="false" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
</div>
Note that I used moment startOf, endOf and toDate to get the first and the last days of the current year as Date objects.

bootstrap date formate getting wrong result

i want date formate in dd/MM/yyyy
using js and css
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
my jquery script
$(function () {
$('#DateOfBirth').datetimepicker({
format: 'dd/mm/yyyy'
});
});
but output is
Tu/00/yyyy
Your format should be like this: "DD/MM/YYYY"
$(function () {
$('#DateOfBirth').datetimepicker({
format: "DD/MM/YYYY"
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div style="position: relative">
<input type="text" id="DateOfBirth" class="form-control" />
</div>

Bootstrap datetime picker doesn't collapse

I'm trying to add date time picker for my mvc 5 application. tried several ways to do it.But it doesn't work.Text box and calender icon is appeared on the view but when i click on the calender it doesn't collapse and show the calender.. why is that?
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<div class="container">
<form action="" class="form-horizontal" role="form">
<fieldset>
<legend>Test</legend>
<div class="form-group">
<label for="dtp_input1" class="col-md-2 control-label">DateTime Picking</label>
<div class="input-group date form_datetime col-md-5" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
<input class="form-control" size="16" type="text" value="" readonly>
<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
</div>
<input type="hidden" id="dtp_input1" value="" /><br />
</div>
</fieldset>
</form>
</div>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">
$('.form_datetime').datetimepicker({
//language: 'fr',
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
});
$('.form_date').datetimepicker({
language: 'fr',
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0
});
$('.form_time').datetimepicker({
language: 'fr',
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 1,
minView: 0,
maxView: 1,
forceParse: 0
});
</script>
According to https://eonasdan.github.io/bootstrap-datetimepicker/Installing/
Minimal Requirements
jQuery
Moment.js
Bootstrap.js (transition and collapse are required if you're not using the full Bootstrap)
Bootstrap Datepicker script
Bootstrap CSS
Bootstrap Datepicker CSS
Locales:Moment's locale files
I create simple demo with your code and get error in console :
Uncaught bootstrap-datetimepicker requires Moment.js to be loaded
first
So just add Moment.js to your app

How do I open a jQuery UI Accordion tab depending on a value in the heading?

I am using ASP Classic and on the page I have a jQuery UI Accordion. I want one tab of the accordion to be open depending on the value of a variable. If the value is equal to 0, I want all the tabs to be closed; if it is greater than 0, I want that Accordion section to be open. This is what I currently have:
jQuery:
$(function() {
$( "#accordion" ).accordion({
heightStyle: "content",
collapsible: true,
active: false
});
});
HTML/ASP:
<div id="accordion">
<h3>Tab1</h3>
<div>
<p>Hello World</p>
</div>
<h3>Tab2</h3>
<div>
<p>Hello World</p>
</div>
<h3>Tab3</h3>
<div>
<p>Hello World</p>
</div>
<h3>Results (<%=number%>)</h3> <!--This is the tab-->
<div>
<p>Hello World</p>
</div>
</div>
Thank you for the help everyone.
I know hundreds of you tried to help but after two attempts of asking the question, I have done it myself. I wish I wasn't a genius, but what is your loss is my gain. If you are remotely interested in how I solved this question then please look below.
jQuery
$Results = '<%=Session("Results")%>';
if ($Results > 0) {
$(function() {
$( "#accordion" ).accordion({
heightStyle: "content",
collapsible: true,
active: 4
});
});
} else {
$(function() {
$( "#accordion" ).accordion({
heightStyle: "content",
collapsible: true,
active: false
});
});
}
HTML/ASP
<div id="accordion">
<h3>Tab1</h3>
<div>
<p>Hello World</p>
</div>
<h3>Tab2</h3>
<div>
<p>Hello World</p>
</div>
<h3>Tab3</h3>
<div>
<p>Hello World</p>
</div>
<h3>Results (<%=Session("intResults")%>)</h3> <!--This is the tab-->
<div>
<p>Hello World</p>
</div>
</div>

Use jQuery DatePicker in Bootstrap 3 modal

I would like to use jQuery UI datepicker in a modal. The real problem is that if I want to also show years and months, it shows me empty selects:
Using firebug, it seems that the option tags are under the modal.
This is my HTML:
<div class="modal-dialog">
<div class="modal-content">
<form id="add-form" action="#" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add</h4>
</div>
<div class="modal-body">
<div class="input-group">
<div class="input-group">
<label for="date">Date</label>
<input type="text" id="date" name="date" class="form-control datepicker"/>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" data-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-primary">Salva</button>
</div>
</form>
</div>
</div>
Javascript:
$( ".datepicker" ).datepicker({
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true
});
$('.datepicker').css("z-index","0");
I already tried this but it doesn't work (I have the same problem of giuseppe).
I found the solution with this answer. The only option you needed is enforceFocus.
Working Demo
jQuery
// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
Only had to add this style:
<style>
.ui-datepicker{
z-index: 9999999 !important;
}
</style>
i could not get $.fn.modal.Constructor.prototype.enforceFocus = function() {}; to work becuase the 'focusin.bs.modal' event was already attached to the modal.
this is the code i got to work; because the date picker is called after the modal opens. using the beforeShow() and onClose function i was able to turn the focus event off and on
var datepicker_opts = {
changeMonth: true,
changeYear: true,
dateFormat: 'mm/dd/yy',
altFormat: "yymmdd",
setDate: new Date(),
maxDate: new Date()
};
BootboxContent = function(){
var frm_str = '<form id="some-form">'
+'<div class="form-group">'
+ '<label for="date">Date</label>'
+ '<input id="date" class="date span2 form-control input-sm" size="16" placeholder="mm/dd/yy" type="text">'
+ '</div>'
+ '</form>';
var object = $('<div/>').html(frm_str).contents();
object.find('.date').datepicker(
$.extend({
beforeShow: function(elem, inst) {
$(document).off('focusin.bs.modal');
},
onClose: function(selectedDate, inst) {
$modal = $(inst.input[0]).closest(".modal").data('bs.modal');
$modal.enforceFocus();
}
}, datepicker_opts)
);
return object
}
$('.add_date_btn').on('click', function () {
bootbox.dialog({
message: BootboxContent,
title: "View modal with date",
buttons: {
cancelar: {
label: "Cancel",
className: "btn-default"
}
}
});
}); //End click
.hidden-form #add_class_form {
display:none;
}
.ui-datepicker{
z-index: 9999999 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://github.com/makeusabrew/bootbox/releases/download/v4.4.0/bootbox.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<button class="add_date_btn btn btn-primary btn-sm">View modal with date</button>

Resources