Im working on a datepicker so when a user hoover over a date it shows date on top of the input bar
Here is the jfiddle im working on http://jsfiddle.net/JGM85/1/
<div class="demo">
<h1></h1>
<p>Date: <input type="text" id="datepicker"></p>
But I am trying to display it content on the side of the datepicker rather than on the top.
Something like this
Imgur Link
You can use beforeshow for datepicker and call your own function.
https://jsfiddle.net/JGM85/272/
Please check this code with your fiddle :
$(function() {
$("#datepicker").datepicker({
//The calendar is recreated OnSelect for inline calendar
onSelect: function (date, dp) {
updateDatePickerCells();
},
onChangeMonthYear: function(month, year, dp) {
updateDatePickerCells();
},
beforeShow: function(elem, dp) { //This is for non-inline datepicker
updateDatePickerCells();
}
});
updateDatePickerCells();
function updateDatePickerCells(dp) {
/* Wait until current callstack is finished so the datepicker
is fully rendered before attempting to modify contents */
setTimeout(function () {
$('.ui-datepicker-calendar').after('<p>Fajr Sunrise Zuhr Asr Magrib Isha</p><div class="className"></div>');
}, 0);
}
$(".ui-state-default").live("mouseenter", function() {
$('.className').html($(this).text()+"."+$(".ui-datepicker-month",$(this).parents()).text()+"."+$(".ui-datepicker-year",$(this).parents()).text());
});
});
You can just make the <p> and the <h1> into : display: inline
<p style="display: inline">
Date: <input type="text" id="datepicker">
</p>
<h1 style="display: inline"></h1>
Related
Quite new to jQuery so please bear with me...
I would like to show the datepicker when I click a button. The datepicker should appear as a popup and assign the selected date to a variable.
My attempt so far
<button type="button" class="btn btn-primary" onclick='snapshot_btn()'>
Snapshot
</button><input type="hidden" id="button_snapshot" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
and in the main.js
function snapshot_btn() {
$("#button_snapshot").datepicker({
showOn: 'both',
onSelect: function () {
var dateObject = $(this).datepicker('getDate');
alert(dateObject);
}
});
}
but the datepicker does not show when I click the button.
It shows normally on other input boxes.
EDIT
Since in your original question you didn't say that it was bootstrap datepicker, not jQuery datepicker, I made this answer using jQuery datepicker.
You need to add the two libraries (jquery and then jquery UI, check the snippet to get the links), after that,
just use the code below and in the onSelect function, get the date as parameter, it already contains the selection.
I made a slight change, removing the input type='hidden', and adding an empty div, that way the calendar will appear inline.
My example also makes the calendar disappear and reappear on click, take a look.
function snapshot_btn() {
var btnOpenCalendar = $("#btnOpenCalendar");
if (btnOpenCalendar.hasClass('calendar-open')){
btnOpenCalendar.removeClass("calendar-open");
$("#button_snapshot").datepicker("destroy");
}else{
btnOpenCalendar.addClass("calendar-open");
$("#button_snapshot").datepicker({
showOn: 'both',
onSelect: function (date) {
alert(date);
}
});
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<button type="button" id='btnOpenCalendar' class="btn btn-primary" onclick='snapshot_btn()'>
Snapshot
</button>
<div id="button_snapshot"></div>
With bootstrap-datepicker, add autoHide:true inside datepicker() and .datepicker("show"); right after. When use click the button, the modal will show up, and hide when you click outside
<button type="button" class="btn btn-primary" onclick='snapshot_btn()'>Snapshot </button>
<input type="hidden" id="button_snapshot" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
JS
function snapshot_btn() {
$("#button_snapshot").datepicker({
autoHide:true,
showOn: 'both',
onSelect: function () {
var dateObject = $(this).datepicker('getDate');
alert(dateObject);
}
});
$("#button_snapshot").datepicker("show");
}
I am trying to implement Bootstrap Datetime picker; Below is the link;
https://fiddle.jshell.net/0sowpm1v/2/
Question 1:
Currently the picker is showing Time as 00:00 even if user is not selecting the time component.
What I am trying to achieve is, If user is not selecting any time then time segment will drop.
If user selects the date as '2015-05-01' then output should be '2015-05-01' instead of '2015-05-01 00:00'.
Question 2:
If this is not possible Can we trigger any function call in 'onClose' event of the picker?
N.B : The concerned Datetime picker is not supporting the 'onClose' event and I am unaware of its equivalent method.
Below is my Code :
<div class="container">
<div class="row">
<div class='col-sm-3'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
This is the JQuery binding of DateTime picker;
$('#datetimepicker1').datetimepicker({
format : "YYYY-MM-DD HH:mm"
});
You can use this code snippet
$('#datetimepicker1').datetimepicker({
format : "YYYY-MM-DD",
autoclose: true,
});
This is just an work around. If any one has better answer, You are welcome to share it.
This is the JQuery workaround that I have implemented.
$('#datetimepicker1').datetimepicker({
format: "YYYY-MM-DD HH:mm",
useStrict: true,
keepInvalid: true
});
$("#datetimepicker1").on("dp.change", function(e) {
if ($('#lblValue').text() == 1) {
$('#lblValue').text('2');
$('#txtDate').val('');
} else if ($('#lblValue').text() == 2) {
$('#lblValue').text('3');
}
});
$("#datetimepicker1").on("dp.hide", function(e) {
if ($('#lblValue').text() == 2 && $('#txtDate').val() == '') {
$('#lblValue').text('4');
} else {
$('#lblValue').text('2');
}
if ($("#txtDate").val() != "" && $("#txtDate").val().trim().substring(16, 10).trim() == "00:00") {
$("#txtDate").val($("#txtDate").val().trim().substring(10, 0));
}
});
I've tried to google and search SO for a similar question, but haven't found anything as of yet.
I have an issue where I create and open a modal from jquery and try to access a date picker, however it doesn't activate the datepickers JS.
$("[id=add]").click(function () {
$("#myModal .modal-header h4").html("Request for Change");
$("#myModal .modal-body").html('<form class="form-horizontal" role="form"><br /><br /><label class="col-sm-2 control-label">Date Required</label><div class="col-sm-3"><div class="input-group date col-sm-8"><input type="text" class="form-control" id="DateRequired"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span></div></div></div>');
$("#myModal").modal("show");
});
(Apologies about the long line length, however I have removed as much as I can - just showing the code which relates to the problem now.)
I have these scripts referenced at the top:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
<script src="~/Scripts/jquery.tablesorter.min.js"></script>
And in the same <script> </script> tag as the jquery function above, at the very top I have:
$('.input-group.date').datepicker({
format: "dd/mm/yyyy",
startDate: "01-01-2015",
endDate: "01-01-2020",
todayBtn: "linked",
autoclose: true,
todayHighlight: true
});
I have this code used in an similar way (except no jquery modal - simply on a cshtml page) that works correctly. I don't know why this way won't work. I've used developer tools to try to trace an issue, but there are no errors - the scripts load correctly however when clicking the Date Required it doesn't fire to the jquery for datepicker.
Am I using the Jquery html wrong to create the modal?
Cheers
The datepicker is hiding behind the modal.
Set datepicker's z-index above the modal's which is 1050.
Additionally wrap your datepicker code in bootstrap's modal shown event.
$('#myModal').on('shown.bs.modal', function() {
$('.input-group.date').datepicker({
format: "dd/mm/yyyy",
startDate: "01-01-2015",
endDate: "01-01-2020",
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
container: '#myModal modal-body'
});
});
$("[id=add]").click(function() {
$("#myModal .modal-header h4").html("Request for Change");
$("#myModal .modal-body").html('<form class="form-horizontal" role="form"><br /><br /><label class="col-sm-2 control-label">Date Required</label><div class="col-sm-3"><div class="input-group date col-sm-8"><input type="text" class="form-control" id="DateRequired"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span></div></div></form>');
$("#myModal").modal("show");
});
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
<style>
.datepicker {
z-index: 1600 !important; /* has to be larger than 1050 */
}
</style>
<div class="well">
<button type="button" id="add">Add</button>
</div>
<div id="myModal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4></h4>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
Note: I added bootstrap v3.3.6 CSS and removed the local reference to the tablesorter script for the demo.
well you have to call the datepicker after modal loaded:
$("[id=add]").click(function() {
$("#myModal .modal-header h4").html("Request for Change");
$("#myModal .modal-body").html('<form class="form-horizontal" role="form"><br /><br /><label class="col-sm-2 control-label">Date Required</label><div class="col-sm-3"><div class="input-group date col-sm-8"><input type="text" class="form-control" id="DateRequired"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span></div></div></div>');
$("#myModal").modal("show");
$('#myModal').on('shown.bs.modal', function(e) {
$('.input-group.date').datepicker({
format: "dd/mm/yyyy",
startDate: "01-01-2015",
endDate: "01-01-2020",
todayBtn: "linked",
autoclose: true,
todayHighlight: true
});
});
});
$('#myModal').on('shown.bs.modal', function (e) {
$('.date').datepicker();
});
It works for me!
$('#modal_form_horizontal').on('shown.bs.modal', function() {
$('.daterangepicker').css('z-index','1600');
});
In a style label, put the following and it worked. The z-index of the modal exceeds that of the datepicker. so place the z-index of the datepicker at 9999
.ui-datepicker {
z-index: 9999 !important;
}
You need to initiate the date picker on the Modal shown event
When using bootstrap (tested with bootstrap 4.3.1) And jquery (3.4.1) jquery ui (1.12.1) for the datepicker and modal. The datepicker will work fine in a modal.
Except if u are also using the class form-control (bootstrap) in your element input.
The css from bootstrap will set the input with the css position: relative. At this moment the datepicker will no longer will be visible.
A other fix to this issue wil be:
.form-control.datepicker {position:unset}
or not using the form-control class
$(document).on('click','#add',function(){
$('.input-group.date').datepicker({
format: "dd/mm/yyyy",
startDate: "01-01-2015",
endDate: "01-01-2020",
todayBtn: "linked",
autoclose: true,
todayHighlight: true
});
})
It is caused by the z-index,
By now you can set manually the z-index of the date picker in your styles.css
/*Date picker container*/ bs-datepicker-container { z-index: 3000; }
By default, modal z-index is 2050. Your datepicker z-index should be more than modal z-index.
Like:
.datepicker {
z-index: 2051 !important;
}
I'm using a datepicker inside my directive to allow user to pick the date. I have disabled the textbox so as to force the user to only change the date using the datepicker widget. The directive is given below:
function InformationDirective(){
return {
restrict: 'A',
link: function (scope, element, attrs, ngModelCtrl) {
var date = document.getElementById('reqDate');
$(date).datepicker($.extend({
dateFormat: 'm/d/y'
}
));
$("#calTrigger-btn").click(function(){
$(date).datepicker("show");
});
}
};
}
The HTML is as below:
<div information-directive>
<input id="reqDate"
ng-model="date"
type="text"
value="{{reqDate}}"
disabled/>
<div type="button" id="calTrigger-btn">
<img id="calendar-img" src="css\images\calendar.gif"></img>
</div>
</div>
For some reason my datepicker will only allow me to pick the date once, after the that the button won't launch the widget again. the $("#calTrigger-btn").click(function() is being called every time I click the button but the widget won't be called after the first selection. The directive and everything are being added to the html, the only problem is that I can't use the datepicker after picking the date once. I am using Jquery-ui-1.8.15 and will not be able to change it to a new one. I wanted to know whether there is any way I can resolve this problem. Any help provided is appreciated. Thank you.
It looks like you're using angular js (which I know nothing about) but if you can set it up as below instead, it works as expected.
$('#reqDate').datepicker($.extend({
dateFormat: 'm/d/y'
}
));
$("#calTrigger-btn").click(function(){
$('#reqDate').datepicker("show");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<div information-directive>
<input id="reqDate"
ng-model="date"
type="text"
value=""
disabled/>
<div type="button" id="calTrigger-btn">
<img id="calendar-img" src="https://cdn2.iconfinder.com/data/icons/windows-8-metro-style/128/calendar.png" width=25 height=25></img>
</div>
</div>
I'm trying to display a datepicker in a popover (using bootstrap and bootstrap-datepicker extension) and having some issues,
first I had a problem with displaying the datepicker and found this topic : Datepicker in Popover Won't display
,but now it's displaying behind my popover so it's not fully visible
Here is the HTML code :
<button type="submit" class="btn btn-primary pop_doleance" rel="popover" data-original-title="Ajouter doléance">Ajouter doléance</button>
<div style="display: none" class="pop_doleance_content">
<form class="well form-inline form_doleance">
<label for="date">Date : </label>
<input id="date" type="text" class="input-medium">
</form>
And the Javascript code :
var tmp = $.fn.popover.Constructor.prototype.show;
$.fn.popover.Constructor.prototype.show = function (){
tmp.call(this);
if (this.options.callback) {
this.options.callback();
}
}
$(function (){
$(".pop_doleance").popover({
placement:'bottom',
html : true,
content: function(){return $('.pop_doleance_content').html();},
callback: function(){$('#date').datepicker();}
});
});
Any ideas ?
set popup's z-index to a lower value.
.popup { z-index : 900; }
and set datepicker's container z-index to a higher value like in case of jquery ui datepicker set
.ui-datepicker-div { z-index: 999; }
In the css I added:
.datepicker {
z-index: 999 !important;
}
Note the "!important". It did not work without this.