Leaving field blank but showing a start hour? - eonasdan-datetimepicker

I am trying to set up start times for the day. When the time picker shows, it keeps saying 12 : 00 AM. I want the times to start at 10 : 00 AM, and increment by 30 minutes. I am using enabledHours to limit the input. I am also using useCurrent: false so that the input field is empty when the page is loaded.
Basically am using this:
format: 'LT',
stepping: 30,
enabledHours: [10, 11, . . . 19],
minDate: moment().hour(10),
useCurrent: false,
showClose: true,
allowInputToggle: true
I have a separate input for the date, all I want to show is the time.
Any help is appreciated.

The easiest way to set starting date for datetime picker is using defaultDate option. Setting this option, the picker input field will be populated with the given date, as you can see in the live example:
$("#datetimepicker1").datetimepicker({
format: 'LT',
stepping: 30,
minDate: moment({hour: 10}),
maxDate: moment({hour: 19, minutes: 30}),
defaultDate: moment({hour: 10}),
useCurrent: false,
showClose: true,
allowInputToggle: true
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<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>
If the input has to be initally blank, then you have to do something a little bit complex. You can listen for dp.show event and set a given date (using date method) if no previous date was set.
Here a live working example:
$("#datetimepicker1").datetimepicker({
format: 'LT',
stepping: 30,
minDate: moment({hour: 10}),
maxDate: moment({hour: 19, minutes: 30}),
useCurrent: false,
showClose: true,
allowInputToggle: true
}).on('dp.show', function(){
var date = $(this).data("DateTimePicker").date();
if( !date ){
var defaultDate = moment({hour: 10});
$(this).data("DateTimePicker").date(defaultDate);
}
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<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>
Please note that I used minDate and maxDate instead of enabledHours, since you are selecting only time. Moreover I used moment({hour: 10}) instead of moment().hour(10) because the first (moment({unit: value, ...});) defaults to 0 for minutes, seconds, milliseconds while the latter takes in account current minutes, seconds etc.

Related

Livewire Datepicker Close after Render on Laravel 8

Suppose I change the start date and click on End Date before render the start date. Then datepicker of End date will be close because of rendering of start date value. If you have any solution or any datepicker suggestion, please help me.
Blade File
<div class="col">
<label for="">Start Date <span class="text-danger">*</span></label>
<input type="text" name="start_date" wire:model.lazy='start_date'
class="form-control #error('start_date') is-invalid #enderror">
#error('start_date')
<small class="text-danger">{{ $message }}</small>
#enderror
</div>
<div class="col">
<label for="">End Date <span class="text-danger">*</span></label>
<input type="text" name="end_date" wire:model.lazy='end_date'
class="form-control #error('end_date') is-invalid #enderror">
#error('end_date')
<small class="text-danger">{{ $message }}</small>
#enderror
</div>
My Script Code for Datepicker
<script>
$('input[name=start_date]').datetimepicker({
format: "DD/MM/YYYY",
disabledDates: false,
useCurrent: false,
showClear: true,
showClose: true,
showTodayButton: true,
});
$('input[name=start_date]').on("dp.change", function(e) {
#this.set('start_date', e.target.value);
});
$('input[name=end_date]').datetimepicker({
format: "DD/MM/YYYY",
disabledDates: false,
useCurrent: false,
showClear: true,
showClose: true,
showTodayButton: true,
});
$('input[name=end_date]').on("dp.change", function(e) {
#this.set('end_date', e.target.value);
});
</script>
If I'm not misunderstand you question why you use "wire:model.lazy" ? "wire:model" remove .lazy might be fixed your problem?

How to disable days is datepicker materializeCSS

I am using materializeCSS datepicker and I only want to select Year and Months
I tried this. Also how to format the date. I want to have it's representation as 2017-07-20
$('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 15,
selectDays: false,
today: 'Today',
clear: 'Clear',
close: 'Ok',
closeOnSelect: false // Close upon selecting a date,
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.0/css/materialize.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.0/js/materialize.min.js"></script>
<div class="input-field">
<input type="date" class="datepicker" name="date" id="date">
</div>
Try this code
$('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 15,
disable: [true],//disable days
today: 'Today',
clear: 'Clear',
close: 'Ok',
closeOnSelect: false // Close upon selecting a date,
});
DEMO

Set predefined date into input type

I want to set predefined date range into datepicker.
When user click button then below date will be set into the input type.
startdate: 1 jan, 2017
enddate: 31 jan, 2017
<script src="js/moment.min.js"></script>
<script src="js/jquery.comiseo.daterangepicker.js"></script>
<input type="text" id="daterangeperiod" name="daterangeperiod" />
You can use setRange method
Sets the selected date range.
It accepts an object with start and end key. Both keys are JavaScript Date objects.
Here a working sample:
$("#daterangeperiod").daterangepicker();
$("#daterangeperiod").daterangepicker("setRange", {
start: new Date(2017, 0, 1),
end: new Date(2017, 0, 31)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdn.rawgit.com/tamble/jquery-ui-daterangepicker/0.5.0/jquery.comiseo.daterangepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet"/>
<link href="https://cdn.rawgit.com/tamble/jquery-ui-daterangepicker/0.5.0/jquery.comiseo.daterangepicker.css" rel="stylesheet"/>
<input type="text" id="daterangeperiod" name="daterangeperiod" />

Bootstrap datepicker - Set maxDate in UTC time instead of local time

I'm using eonasdan bootstrap-datetimepicker. I'm trying to work in UTC time (including hours) but maxDate seems to refer to local time.
An example would be if I want to limit the time to 10:00 am UTC time. I want the datetimepicker to allow time modification but no longer than 10:00 am UTC time. Because I'm +3 timezone, I'm able to go until 13:00 pm.
Here is the fiddle: http://jsfiddle.net/vvtwq0xm/1/
var dateUTCtime = new Date().toISOString();
alert('UTC time = ' + dateUTCtime);
var opts = {
format: "DD-MMM-YYYY HH:mm",
stepping: 5,
maxDate: dateUTCtime,
useCurrent: true,
sideBySide: false,
showTodayButton: true,
widgetPositioning: {
'vertical': 'bottom'
}
};
$('#datetimepicker1').datetimepicker();
My date is in UTC but maxTime seems to not respect time (hour) to UTC. It allows me to go until current local time.
Anyway to make it work on UTC?
ps: I added some explanation for better understanding. I'm interested in respecting UTC date and time (hours).
In version 4.17.37 timezone integration was added (see changelog), while you are using version 4.14.30 of the datetimepicker in your fiddle.
To use the picker with UTC, add moment-timezone to your imports and set maxDate using moment.utc().
Here a working example (using lastest picker version: 4.17.42):
var opts = {
format: "DD-MMM-YYYY HH:mm",
stepping: 5,
maxDate: moment.utc(),
useCurrent: true,
sideBySide: false,
showTodayButton: true,
widgetPositioning: {
'vertical': 'bottom'
}
};
$('#datetimepicker1').datetimepicker(opts);
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.5/moment-timezone-with-data-2010-2020.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.42/js/bootstrap-datetimepicker.min.js"></script>
<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>

jquery date time picker minDate / maxDate issue

the code below was working perfectly fine before but recently I noticed that the minDate/maxDate isn't working anymore, strange because I didn't make any change on the code. I have been struggling with this for a few days now, it's annoying.
I am using this -- http://mugifly.github.io/jquery-simple-datetimepicker/
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://mugifly.github.io/jquery-simple-datetimepicker/jquery.simple-dtpicker.js"></script>
<link type="text/css" href="http://mugifly.github.io/jquery-simple-datetimepicker/jquery.simple-dtpicker.css" rel="stylesheet" />
<input type="text" name="start_time" id="start_time">
<input type="text" name="end_time" id="end_time">
<script type="text/javascript">
$(function(){
$('#end_time').change(function() {
$('#start_time').appendDtpicker({
"futureOnly": true,
"closeOnSelected": true,
"dateFormat": "DD/MM/YYYY hh:mm",
"minTime":"07:00",
"maxTime":"23:00",
maxDate: $('#end_time').val() // when the end time changes, update the maxDate on the start field
});
});
$('#start_time').change(function() {
$('#end_time').appendDtpicker({
"futureOnly": true,
"closeOnSelected": true,
"dateFormat": "DD/MM/YYYY hh:mm",
"minTime":"07:00",
"maxTime":"23:00",
minDate: $('#start_time').val() // when the start time changes, update the minDate on the end field
});
});
// trigger change event so datapickers get attached
$('#end_time').trigger('change');
$('#start_time').trigger('change');
});
</script>