I'm using the bootstrap datetime picker, the documentation of which can be found here: https://eonasdan.github.io/bootstrap-datetimepicker/Options/
I'm trying to set the selected date to null. I'm able to blank out the date (i.e. 2/10/2019) within the input field, but when I click on the input field and the calendar opens, the old date is still selected in blue. WiThis is my code to de-select all dates within the calendar.
$(document).ready(function() {
$('.removedate').on('click', function(){
$("#id_booking_date").val('') //this correctly removes date from input field
$('.input-group').datetimepicker({
date: new Date(null)
});
});
This code isn't working. Do you know what I should try?
Thanks!
Can you please try to use "useCurrent" option for this? Check it out here https://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent
Please try this, they have clearly mentioned here
Working example:
$('#datetimepicker4').datetimepicker({
useCurrent: false,//
});
Related
When I click on datetimepicker current date automatically gets populated in input field. I want that it should populate only when I select a date in popup box. Is there any flag to do it ?
$('#datetimepickerStartDate').datetimepicker({
format: 'DD-MMM-YYYY'
});
Ok. I got the solution. It can be done by setting "useCurrent" to false.
Setting the useCurrent option to false will disable this functionality:
$('#datetimepickerStartDate').datetimepicker({
useCurrent: false
});
I have 2 text boxes namely fromDate & toDate for date search , in which by default, current day will be showed.
working code:
Jquery
(document).ready(function () {
$('.dateClass').datetimepicker({timepicker: false}); // css for displaying date without time
$('#fromDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'}); // display current date with dd-mmm-yyyy
$('#toDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'}); // display current date with dd-mmm-yyyy
});
Struts
<html:text property="fromDate" styleId="fromDateId" styleClass="dateClass" />
<html:text property="toDate" styleId="toDateId" styleClass="dateClass" />
Issue:
By default current day shown in both textboxes, suppose user choose different dates and submit,
db records are fetched and displayed but these 2 texboxes replaced with current dates how to avoid this.
kindly help me to resolve.
Update: There are reports this no longer works in Chrome.
This is concise and does the job:
$(".fromDateId").datepicker('setDate', new Date());
And another thing,
$(function()
{
$('.date-pick').datePicker().val(new Date().asString()).trigger('change');
});
I'm using this extension of Bootstrap's datepicker. It works well enough, but I've come upon a usability issue - when selecting a date/time, the text field the datepicker is attached to does not update unless all the steps (year/month/day/hour/minute) are selected to the end. Clicking away from the datepicker before clicking all the steps yields no change to the date in the text field.
How do I make it so that when the user clicks away mid-selection (maybe because they just want to change the date, but find the already-present hour and minute to be acceptable), the text field is updated appropriately?
For example:
Initial date in field: 2015/10/10 10:00
Click on 2015/10/15 -> click away -> date in field: 2015/10/15 10:00
Is that even possible?
Check this updated fiddle - https://jsfiddle.net/4cqLcxcm/8/
Added on changeDay event on datepicker, which will trigger on change of date and set that value into input box.
Below is the code I have changed.
$(document).ready(function() {
var now = new Date();
$('#send-time').datetimepicker({
format: 'yyyy/mm/dd hh:ii',
startDate: now
})
.on('changeDay', function(ev){
$('#send-time').datetimepicker('update',ev.date);
});
console.log('test');
});
I use a calendar from No Gray, found at http://www.nogray.com/calendar.php, and I have realised that the problems I have been having is due to when you click on the same date that has already been selected, it deselects the date instead of reselecting it again and if it is passed through in a form, the value for that field is empty.
I have read up on the use of the software and the options and the only option I can see that may help is the "ng.Calendar.is_selected" found at http://www.nogray.com/api/calendar/is_selected.php, and I am not sure if that is correct, but even on their demo on their own website, it works the same way and deselects the date instead of reselecting it.
I have tried everything but can't get it to perform where if you click the same date that is already selected, it does not deselect the date and just reselects it.
The example is here http://www.nogray.com/example.php?ID=260.
How can this been done please as I have tried now for a week with no joy.
Thank you in advance.
This example might help, but the user won't be able to unselect a date unless they clear the input field.
<input id="forced_click_select" type="text">
<script src="PATH/TO/ng_all.js" type="text/javascript"></script>
<script src="PATH/TO/components/calendar.js" type="text/javascript"></script>
<script type="text/javascript">
ng.ready( function() {
var fcs_cal = new ng.Calendar({
input: 'forced_click_select',
events: {
onDateClick: function(dt){
this.select_date(dt);
}
}
})
});
</script>
http://www.nogray.com/example.php?ID=307
I am trying to make a datepicker work. The datepicker pops up when you click a calendar icon right next to an input field. When a use clicks the icon, and selects a date, the input field should populate with the date. This works if i do not try to format the date, but as soon as i do, i get an
'Cannot read property "formatDate" of undefined'
The icon of a calendar has a class of '.calendar'. Here is my code for when they click that icon.
$('.calendar').datepicker({
format: 'mm/dd/yy',
startDate: '-1'
}).on('changeDate', function (ev) {
$(this).prev('input').val(
$.datepicker.formatDate('mm/dd/y', ev.date)
);
$(this).datepicker('hide');
});
As soon as it hits
$(this).prev('input').val(
$.datepicker.formatDate('mm/dd/y', ev.date)
);
It stops working. What am i doing wrong here?
If you just do $(this).prev('input').val(ev.date); it works perfect, but that format is wrong, and it will not go into my database.
Thank you in advance.