After choose time I get undefined - javascript

After I choose a time and submit a form, I get undefine
When I open console, there aren't any error.
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 30,
minTime: '10',
maxTime: '3:00pm',
startTime: '10:00',
dynamic: true,
dropdown: true,
scrollbar: true
});
$(function () {
$("#datepicker").datepicker({
minDate: +1, maxDate: "+3M"
});
});
$(document).ready(function () {
var appointmentTime = document.getElementById('datepicker').value;
var splitData = "";
if (appointmentTime.indexOf("") > 0) {
splitData = appointmentTime.split(" ");
}
else {
splitData = appointmentTime.split("T");
}
var time = splitData[1].substring(0, 5);
if (time.slice(-1) == ":") {
time = time.substring(0, time.length - 1);
}
var amPmTime = splitData[2];
$('#datepicker').attr('value', splitData[0]);
$('#timepicker').attr('value', time + ' ' + amPmTime);
});
And in my field I get something like this:
Image
Any idea what could be problem ?

Related

loop available dates, select one of them and fill the input box

I am trying to fill in the input that is normally filled by a js code inside the html:
<input type="text" readonly="" class="form-control-input app_date validate" style="width: 260px;" id="app_date" name="app_date" placeholder="YYYY-MM-DD" onchange="this.form.submit();showLoader();" value="" autocomplete="off">
js code got from html
import re
html = """
<script type="text/javascript">
var dt4 = '2019-03-07';
var blocked_dates = ["20-03-2019","01-01-1970","28-03-2019","29-03-2019","20-03-2019","01-01-1970","28-03-2019","29-03-2019"];
var available_dates = ["07-03-2019","08-03-2019","11-03-2019","12-03-2019","13-03-2019","14-03-2019","15-03-2019","18-03-2019","19-03-2019","21-03-2019","22-03-2019","25-03-2019","26-03-2019","27-03-2019"];
var fullCapicity_dates = [];
var offDates_dates = ["09-03-2019","10-03-2019","16-03-2019","17-03-2019","20-03-2019","23-03-2019","24-03-2019","28-03-2019","29-03-2019","30-03-2019","31-03-2019"];
var allowArray = [1];
</script>
"""
i successfully captured the available dates :
date_list = re.findall(r'var\s*available_dates\s*=\s*\[[^\]]+', html)
if date_list:
for av_date in re.findall(r"\"[0-9\-]+\"",date_list[0]) :
print(av_date.replace('"',''))
Break
else : print("no available dates")
output :
07-03-2019 08-03-2019 11-03-2019 12-03-2019 13-03-2019 14-03-2019
15-03-2019 18-03-2019 19-03-2019 21-03-2019 22-03-2019 25-03-2019
26-03-2019 27-03-2019
I don't know how to loop the availables dates , select one of them and fill the input and continue the py script. if no available dates keep refreshing the current page until available dates are found. i am confused is it a while loop, a while true or if ?
full js code
<script type="text/javascript">
var today = new Date();
var dd = today.getDate()+1;
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
var today = yyyy+'-'+mm+'-'+dd;
function formatDate(rawDate) {
var day = ("0" + rawDate.getDate()).slice(-2);
var month = ("0" + (rawDate.getMonth() + 1)).slice(-2);
return (day)+ "-" + (month)+ "-" +rawDate.getFullYear() ;
}
$(document).ready(function() {
var dt1 = '2019-03-06';
var checkService = 'Normal';
$('#dateOfBirth').datepicker({
format: "yyyy-mm-dd",
endDate: new Date(dt1),
startDate: '-100y',
autoclose: true,
startView: 2
});
$('#pptIssueDate').datepicker({
format: "yyyy-mm-dd",
endDate: new Date(dt1),
startDate: '-100y',
autoclose: true,
startView: 2
});
$('#pptExpiryDate').datepicker({
format: "yyyy-mm-dd",
startDate: new Date(dt1),
autoclose: true,
startView: 2
});
var dt4 = '2019-03-07';
var blocked_dates = ["20-03-2019","01-01-1970","28-03-2019","29-03-2019","20-03-2019","01-01-1970","28-03-2019","29-03-2019"];
var available_dates = ["07-03-2019","08-03-2019","11-03-2019","12-03-2019","13-03-2019","14-03-2019","15-03-2019","18-03-2019","19-03-2019","21-03-2019","22-03-2019","25-03-2019","26-03-2019","27-03-2019"];
var fullCapicity_dates = [];
var offDates_dates = ["09-03-2019","10-03-2019","16-03-2019","17-03-2019","20-03-2019","23-03-2019","24-03-2019","28-03-2019","29-03-2019","30-03-2019","31-03-2019"];
var allowArray = [1];
if(checkService == 'Normal')
{
/*if((jQuery.inArray(2, allowArray)!='-1') || (jQuery.inArray(3, allowArray)!='-1'))
{
var classFull = 'fullcapspecial';
var tooltipTitle = ' ';
var backDatetitle = 'Not Allowed';
}else{
var classFull = 'fullcap';
var tooltipTitle = 'Slots Full';
var backDatetitle = 'Not Allowed';
}*/
var classFull = 'fullcap';
var tooltipTitle = 'Slots Full';
var backDatetitle = 'Not Allowed';
}else{
var classFull = 'fullcap';
var tooltipTitle = 'Slots Full';
var backDatetitle = 'Not Allowed';
}
$('.app_date').datepicker({
language: "en",
Default: true,
format: "yyyy-mm-dd",
startDate: new Date(dt4),
endDate: '2019-03-31',
autoclose: true,
forceParse:true,
startView: 0,
beforeShowDay: function(date){
var formattedDate = formatDate(date);
if ($.inArray(formattedDate.toString(), blocked_dates) != -1){
return {
enabled : false,
classes: 'inactiveClass',
tooltip: 'Holiday'
};
}
if ($.inArray(formattedDate.toString(), available_dates) != -1){
return {
enabled : true,
classes: 'activeClass',
tooltip: 'Book'
};
}
if ($.inArray(formattedDate.toString(), fullCapicity_dates) != -1){
return {
enabled : false,
classes: classFull,
tooltip: tooltipTitle
};
}
if ($.inArray(formattedDate.toString(), offDates_dates) != -1){
return {
enabled : false,
classes: 'offday',
tooltip: 'Off Day'
};
}
return {
enabled : false,
tooltip: backDatetitle
};
return;
}
});
/*====== CALL POP FOR PL/PT IN NORMAL CASE=======*/
if(checkService == 'Normal')
{
if((jQuery.inArray(2, allowArray)!='-1') || (jQuery.inArray(3, allowArray)!='-1'))
{
/*$(document).on('click', '.fullcap,.fullcapspecial', function () {
$(".datepicker").hide();
$('.popupBG').show();
$('#IDBodyPanel').show();
});
$(".popupCloseIcon").click(function() {
$(".popupBG").hide();
$("#IDBodyPanel").hide();
});
$('input[type=radio][name=serviceChange]').change(function() {
if (this.value == 'Premium') {
$("#premiumService").prop('value', 'GO FOR PREMIUM');
}
else if (this.value == 'Prime') {
$("#premiumService").prop('value', 'GO FOR PRIME TIME');
}
});*/
}
}
/*====== CALL POP FOR PL/PT IN NORMAL CASE=======*/
var eventhandler = function(e) {
e.preventDefault();
}
if (checkService == 'Premium' || checkService == 'Prime') {
$('input[name="vasId[]"]:checked').each(function() {
$("#vasId"+this.value).bind('click', eventhandler);
});
}
if (checkService != 'Premium')
{
$(document).on('click', '.chkbox', function () {
if($(this).val() == 1)
{
if($(this).is(":checked")){
//$("#vasId6").prop('checked', true);
//$("#vasId6").bind('click', eventhandler);
}else{
//$("#vasId6").prop('checked', false);
//$("#vasId6").unbind('click', eventhandler);
}
}
});
}
});
</script>

I have problem with datepicker dateDisnable

I hava a problem with use datepicker bootstrap v1.5.0
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('.checkin').datepicker({
todayHighlight:'TRUE',
autoclose: true,
beforeShowDay: function(date) {
return date.valueOf() >= now.valueOf();
},
datesDisabled :test,
}).on('changeDate', function(ev) {
$(this).datepicker('hide');
if (ev.date.valueOf() > checkout.datepicker("getDate").valueOf()
|| !checkout.datepicker("getDate").valueOf()) {
var newDate = new Date(ev.date);
newDate.setDate(newDate.getDate() + 1);
checkout.datepicker("update", newDate);
}
});
var checkout = $('.checkout').datepicker({
beforeShowDay: function(date) {
if (!checkin.datepicker("getDate").valueOf()) {
return date.valueOf() >= new Date().valueOf();
} else {
return date.valueOf() > checkin.datepicker("getDate").valueOf();
}
},
autoclose: true,
datesDisabled :daylist,
}).on('changeDate', function(ev) {});
when I choose date of my checkin input, my checkout input not display, but when i press tab and click again, it display and with error
enter image description here
It appears you may have syntax errors:
remove comma ","
datesDisabled :test,
datesDisabled :test
and also here:
datesDisabled :daylist,
datesDisabled :daylist

How to re-initialize the bootstrap datetimepicker?

I have a Two datetimepicker on my page. Name as 'SartDate' and 'EndDate'.Select the date on StartDate, this date set as a minDate of 'EndDate'.First time is work Correctly.But the date of 'StartDate' reset, the minDate of 'EndDate' Not
re-initiliaz
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
$('#jobPublishDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true });
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" +from[2];
var f = new Date(newdate);
date = f;
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
});
<label>StartDate></label>
<input ng-model="job.StrPublishDate" id="jobPublishDate">
<br/>
<label>EndDate></label>
<input ng-model="job.StrCloseDate" id="jobCloseDate">
You need to hook to the dp.change event (fired when the date has been selected) an use minDate method to set the minimum date on the second picker.
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
$('#jobPublishDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true })
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" +from[2];
var f = new Date(newdate);
date = f;
});
// Adds the date change event to the first picker
$("#jobPublishDate").on('db.change', function (e) {
// Get the DateTimePicker instance
var dp = $('#jobCloseDate').data('DateTimePicker');
// If the second picker has been initialized
if(typeof dp !== 'undefined') {
// Set the minimum date on the second picker
dp.minDate(e.date);
} else {
// If the close date picker is not initialized, stores the date for later use
date = e.date;
}
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
You can find out more about DateTimePicker methods here.
var date = null;
$("#jobPublishDate").bind("keyup blur change mouseup", function () {
var from = $("#jobPublishDate").val().split("/");
var newdate = from[1] + "/" + (from[0]) + "/" + from[2];
var f = new Date(newdate);
date = f;
$("#jobPublishDate").on('dp.change', function (e) {
var dp = $('#jobCloseDate').data('DateTimePicker');
if (typeof dp !== 'undefined') {
dp.minDate(e.date);
}
else {
date = e.date;
}
});
$("#jobCloseDate").focusin(function () {
$('#jobCloseDate').datetimepicker({ format: 'DD/MM/YYYY H:mm', showTodayButton: true, showClear: true, showClose: true, minDate: date });
});
Fellow this Code and Solve the Problem.

Bootstrap - Datepicker/Disable specific dates from array

I have a array with dates. I want to loop this array and disable selectable dates in datepicker control. I need to do this in beforeShowDay parameter!
This is my code:
var datesForDisable = ["25-01-2017", "26-01-2017", "27-01-2017"]
$("#holidayDateFrom").datepicker({
format: 'dd-mm-yyyy',
autoclose: true,
weekStart: 1,
calendarWeeks: true,
todayHighlight: true,
//datesDisabled: datesForDisable,
//daysOfWeekDisabled: [0, 6],
beforeShowDay: function (currentDate) {
var dayNr = currentDate.getDay();
if (dayNr == 6) {//This works
return false;
}
if (dayNr == 0) {//This works
return false;
}
// This dosnt works..
var dateNr = moment(currentDate.getDate()).format("DD-MM-YYYY");
if (datesForDisable.length > 0) {
for (var i = 0; i < datesForDisable.length; i++) {
var date = new Date(datesForDisable[i]);
if (date == dateNr) {
return false;
}
}
}
return true;
}
})
How to do this? Thank you previously!
You can compare the dates as timestamp(unix time)
var datesForDisable = ["25.01.2017", "26.01.2017", "27.01.2017"]
$("#datepicker").datepicker({
format: 'dd/mm/yyyy',
autoclose: true,
weekStart: 1,
calendarWeeks: true,
todayHighlight: true,
//datesDisabled: datesForDisable,
//daysOfWeekDisabled: [0, 6],
beforeShowDay: function (currentDate) {
var dayNr = currentDate.getDay();
var dateNr = moment(currentDate.getDate()).format("DD-MM-YYYY");
if (dayNr == 6) {//This works
return false;
}
if (dayNr == 0) {//This works
return false;
}
if (datesForDisable.length > 0) {
for (var i = 0; i < datesForDisable.length; i++) {
if (moment(currentDate).unix()==moment(datesForDisable[i],'DD.MM.YYYY').unix()){
return false;
}
}
}
return true;
}
})
datesDisabled: datesForDisable
I am not sure why you comment this option. As per your question, This option is providing the same thing you are look for. Take a look:
http://jsfiddle.net/CxNNh/4056/
Its worked perfect for me
var datesForDisable = ["03-04-2019", "03-09-2019", "03-15-2019"];
$(document).ready(function () {
$('.datepicker').datepicker({
multidate: true,
format: 'mm-dd-yyyy',
todayHighlight: false,
datesDisabled: datesForDisable,
multidateSeparator: ', ',
templates : {
leftArrow: '<i class="fi-arrow-left"></i>',
rightArrow: '<i class="fi-arrow-right"></i>'
}
});
});

datetimepicker update mindate maxdate

I am using jquery datetimepicker for two textboxes From date To date. I want to update the values mindate and maxdate from the other text box. The first time it is working fine but if I change the values on debug are correct but the datetimepicker doesnt update. My question is how I will make datetimepicker to update. Reading the code I think it is more clear. Thank you
$(".DatePickerFieldOnHire").live('click', function () {
var defaultDateTime = "";
var dateFrom = "";
var dateTo = "";
dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;
var now = new Date();
var dateNow=now.format("dd-mm-yy HH:mm z");
dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;
var now = new Date();
var dateNow=now.format("dd-mm-yy HH:mm z");
if (dateFrom == null) {
dateFrom = new Date(1999, 10 - 1, 25);
}
if (dateTo == null) {
dateTo = new Date(2055, 10 - 1, 25);
defaultDateTime = dateNow;
} else {
if (dateTo > dateNow) {
defaultDateTime = dateNow;
}
else {
defaultDateTime = dateTo;
}
}
var inputOff = "";
inputOff = $('[id*="OffHireDateField"]').val();
if (inputOff != "") {
dateFrom = inputOff;
}
$(this).datetimepicker({
showOn: 'focus', showTimezone: false, ampm: true, dateFormat: "dd-mm-yy",
timeFormat: "HH:mm z",
minDate: dateFrom,
maxDate: dateTo,
showTimezone: true,
defaultDate: defaultDateTime,
onSelect: function () { }
}).focus();
});
and the From textbox
$(".DatePickerFieldOffHire").live('click', function () {
var dateFrom = "";
var dateTo = "";
dateFrom = document.getElementById('WebReportForm1_Value_DeliveryDate').value;
dateTo = document.getElementById('WebReportForm1_Value_ExpectedRedeliveryDate').value;
if (dateFrom == null) {
dateFrom = new Date(1999, 10 - 1, 25);
}
if (dateTo == null) {
dateTo = new Date(2055, 10 - 1, 25);
defaultDateTime = dateNow;
} else {
if (dateTo > dateNow) {
defaultDateTime = dateNow;
}
else {
defaultDateTime = dateTo;
}
}
var inputOn = "";
inputOn = $('[id*="OnHireDateField"]').val();
if (inputOn != "") {
dateTo = inputOn;
}
$(this).datetimepicker({
showOn: 'focus', showTimezone: false, ampm: true, dateFormat: "dd-mm-yy",
timeFormat: "HH:mm z",
minDate: dateFrom,
maxDate: dateTo,
showTimezone: true,
defaultDate: defaultDateTime,
onSelect: function () { }
}).focus();
});
I have to admit, I did not check the code thoroughly as you have not included a JSFiddle, but from what I can see, it looks like the first time, dateFrom and dateTo are Date objects but from the second time on they are Strings.
This might be an issue.
Your date format dd-mm-yy does not comply with the default format yy-mm-dd.

Categories

Resources