Jquery ui datepicker disappears on android mobile - javascript

I have a big trouble with android mobile on my web site when I click my calendar datepicker appears and after keyboard hiding my datepicker hides, I couldn't find the problem for months.
On IOS and desktop version I have no problem and I have this trouble only with android devices.
I don't think problem is about with my calendar function but I want to share with you:
var dateFormat = "DD/MM/YY",
from = $("#checkin,.checkin").datepicker({
firstDay: 1,
minDate: 0,
showButtonPanel: true,
closeText: 'Temizle',
onClose: function(dateText, inst) {
},
onSelect: function(selectedDate) {
window.setTimeout($.proxy(function() {
$(this).parents(".book-holiday").find("#checkout,.checkout").focus();
}, this), 10);
var yenitarih = new Date();
var date = $(this).datepicker('getDate');
var checkoutStartDate = new Date(new Date(date).setDate(date.getDate() + 1));
var checkoutEndDate = new Date(new Date(date).setDate(date.getDate() + 500000));
$("#checkout,.checkout").datepicker("option", "minDate", checkoutStartDate);
$("#checkout,.checkout").datepicker("option", "maxDate", checkoutEndDate);
},
isTo1: true,
beforeShowDay: function(date) {
var selectedDate = $(this).datepicker('getDate'),
fromDate = from.datepicker('getDate');
if (!fromDate || !selectedDate) {
return [true]
}
var dateClass = '';
var dateClass = '';
if (date > fromDate && date < selectedDate) {
dateClass = 'start';
} else if (+date == +selectedDate) {
dateClass = 'stop';
}
return [true, dateClass];
},
beforeShow: function(input, inst) {
$(this).datepicker("widget").addClass("main-datepicker");
controlDatepicker(".checkin,#checkin");
}
});
$("#checkout,.checkout").datepicker({
firstDay: 1,
minDate: 0,
showButtonPanel: true,
closeText: 'Temizle',
onClose: function(dateText, inst) {
},
isTo1: true,
onSelect: function(selectedDate) {
$(this).parents(".book-holiday").find(".popover-wrapper").addClass("open");
$(this).parents(".book-holiday").find(".popover-wrapper").addClass("open");
},
beforeShowDay: function(date) {
var selectedDate = $(this).datepicker('getDate'),
fromDate = from.datepicker('getDate');
if (!fromDate || !selectedDate) {
return [true]
}
var dateClass = '';
if (date > fromDate && date < selectedDate) {
dateClass = 'start';
} else if (+date == +selectedDate) {
dateClass = 'stop';
}
return [true, dateClass];
},
beforeShow: function(input, inst) {
$(this).datepicker("widget").addClass("main-datepicker");
controlDatepicker(".checkin,#checkin");
}
I set readonly to my datepicker input but when I click it keyboard is showing I don't understand why is it opening ?
and I want to share my web site: click to see - please check it out on android devices and click to datepicker

Related

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

Is DateTimePicker cannot disable past time?

I want to disable past time and date based on my selection of start date and end date. I was able to disable my date, but it won't work on time.
Example:
Start Date - 24-May-2019 01:30 PM
End Date - 24-May-2019 01:00 PM < suppose to not be able to choose an earlier time
i tried this function, but while disable past date is working fine, still cannot for time
onSelect: function (selectedDate) {
var endYear = $(this).datetimepicker('getFullYear');
var endMonth = $(this).datetimepicker('getMonth');
var endDay = $(this).datetimepicker('getDate');
var endHour = $(this).datetimepicker('getHours');
var endMinutes = $(this).datetimepicker('getMinutes');
var endSeconds = $(this).datetimepicker('getSeconds');
("#endDate").datetimepicker("option", "minDate", new Date(endYear, endMonth, endDay, endHour, endMinutes, endSeconds));
}
onSelect: function (selectedDate) {
var endYear = $(this).datetimepicker('getFullYear');
var endMonth = $(this).datetimepicker('getMonth');
var endDay = $(this).datetimepicker('getDate');
var endHour = $(this).datetimepicker('getHours');
var endMinutes = $(this).datetimepicker('getMinutes');
var endSeconds = $(this).datetimepicker('getSeconds');
$("#startDate").datetimepicker("option", "maxDate", new Date(endYear, endMonth, endDay, endHour, endMinutes, endSeconds));
}
also tried this function below, but also not working
onSelect: function (selectedDate) {
$("#endDate").datetimepicker("option", "minDate", selectedDate);
$("#endDate").datetimepicker("option", "minTime", selectedDate);
}
onSelect: function (selectedDate) {
$("#startDate").datetimepicker("option", "maxDate", selectedDate);
$("#startDate").datetimepicker("option", "maxTime", selectedDate);
}
current working code (that disable past date only):
for start date
onSelect: function (selectedDate) {
$("#endDate").datetimepicker("option", "minDate", selectedDate);
}
WORKING CODE
added an onClose function to read the time
for example :
if user select start date 05-May-2019 5:00 AM and end date 05-May-2019 3:00 AM
the start date value will automatically update to 05-May-2019 3:00 AM
for end date
onSelect: function (selectedDate) {
$("#startDate").datetimepicker("option", "maxDate", selectedDate);
}
for startDate
onClose: function (dateText, inst) {
var startDateSelect = $('#startDate');
var endDateSelect = $('#endDate');
if (endDateSelect.val() != '') {
var sDate = startDateSelect.datetimepicker('getDate');
var eDate = endDateSelect.datetimepicker('getDate');
if (sDate > eDate)
endDateSelect.datetimepicker('setDate', sDate);
}
else {
endDateSelect.val(dateText);
}
},
onSelect: function (selectedDate) {
$("#endDate").datetimepicker("option", "minDate", selectedDate);
}
for endDate
onClose: function (dateText, inst) {
var startDateSelect = $('#startDate');
var endDateSelect = $('#endDate');
if (startDateSelect.val() != '') {
var sDate = startDateSelect.datetimepicker('getDate');
var eDate = endDateSelect.datetimepicker('getDate');
if (sDate > eDate)
startDateSelect.datetimepicker('setDate', eDate);
}
else {
startDateSelect.val(dateText);
}
},
onSelect: function (selectedDate) {
$("#startDate").datetimepicker("option", "maxDate", selectedDate);
}
For using jquery DateTimePicker, there are option for setting the min/max time as well.
use minTime or maxTime for times
use minDate or maxDate for dates
Working example: https://jsfiddle.net/qy48so6d/1/
$('#datetimepicker').datetimepicker({
minDate:'2019/05/01',
maxDate:'2019/05/02',
minTime:'01:00',
maxTime:'02:00'
});
Reference: https://xdsoft.net/jqplugins/datetimepicker/#minTime
If you are using https://trentrichardson.com/examples/timepicker/
you can try this
$("#endDate").datetimepicker("option", "minDateTime", selectedDate);
// or
$("#endDate").datetimepicker("option", "minTime", '8:00 am');
Example
$(document).ready(function() {
var startDateTextbox = $('#startDate')
var endDateTextbox = $('#endDate')
startDateTextbox.datetimepicker({
onSelect: function(selectedDate) {
endDateTextbox.datetimepicker('option', 'minDate', startDateTextbox.datetimepicker('getDate'))
endDateTextbox.datetimepicker('option', 'minTime', '8:00 am')
endDateTextbox.datetimepicker('option', 'maxTime', '9:00 am')
}
});
endDateTextbox.datetimepicker({
minTime: '8:00 am'
});
})

ui-datepicker-div is empty in angular directive

I am using ui-datepicker and it is working fine on chrome but not on safari. I have also tried by putting CSS file first and then JS file in my main index.html file. It is generating ui-datepicker-div in bottom but it is empty on Safari.
Here is HTML i am using:
<input type="image" src="images/calendar-icon.jpg" ng-model="selectedWeek" weekpicker format="yy-mm-dd" style="margin-left:10px;" />
and here is JavaScript i am using:
myApp.directive('weekpicker', function () {
function link(scope, element, attrs, ngModelCtrl, $rootScope) {
var frmt = "mm/dd/yy";
if (attrs.format != undefined) {
frmt = attrs.format;
} else if (attrs.placeholder != undefined) {
frmt = attrs.placeholder;
}
scope.getSunday = function(fromDate) {
var curr = new Date(fromDate); // get current date
var first = curr.getDate() - curr.getDay(); // First day is the day of the month - the day of the week
var firstday = new Date(curr.setDate(first)).toUTCString();
return firstday;
};
scope.getWeekDaysRange = function (inputDateString) {
return scope.getDates(new Date(inputDateString), (new Date(inputDateString)).addDays(6));
};
scope.getDates = function(startDate, stopDate) {
var dateArray = new Array();
var currentDate = startDate;
while (currentDate <= stopDate) {
var curdate = new Date(currentDate);
var dateElements = {
day : cal_days_labels[curdate.getDay()],
date : curdate.getDate(),
month : cal_months_labels[curdate.getMonth()],
year : curdate.getFullYear(),
datestamp : curdate.getFullYear()+''+scope.padWithZero(curdate.getMonth()+1)+''+scope.padWithZero(curdate.getDate())
};
dateArray.push(dateElements);
currentDate = currentDate.addDays(1);
}
return dateArray;
};
scope.padWithZero = function(number) {
if(number>-10 && number<10) {
number = '0'+number;
}
return number;
};
$(element).datepicker({
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true,
showWeek: true,
beforeShow: function(dateText, inst) {
},
onSelect : function(dateText, inst) {
current = {day: inst.currentDay, month : inst.currentMonth, year : inst.currentYear};
var selectedDateString = new Date(current.year+'-' + (1+current.month) + '-' + current.day);
var weekBoundryDates = selectedDateString.getWeekBoundryDaysFromToday();
var weekBoundries = weekString(weekBoundryDates);
scope.$apply(function() {
scope.selectedWeek = weekBoundries;
});
scope.$digest();
scope.$emit("weekselected", inst);
},
onClose: function(dateText, inst) {
}
});
scope.$watch(function(scope){
return scope.selectedWeek;
}, function(newVal, oldVal){
});
};
return {
restrict: 'A',
require: 'ngModel',
link: link
};
});
the above code is working fine in Chrome, but not in Safari.
Can anyone help me please.
Change input type image to text it will work :)
<input type="text" src="images/calendar-icon.jpg" ng-model="selectedWeek" weekpicker format="yy-mm-dd" style="margin-left:10px;" />

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.

Disable days in Datepicker

I'm trying to disable certain days of the calendar, but I can not.
I'm using this datepicker https://github.com/eternicode/bootstrap-datepicker/blob/master/docs/index.rst.
The javascript code I have is this, I work all I need except the days you want to disable.
var disabledDays = ['11/29/2013', '11/27/2013', '11/28/2013'];
function daysDisabled(date) {
for (var i = 0; i < disabledDays.length; i++) {
if (new Date(disabledDays[i]).toString() == date.toString()) {
return [false, ''];
}
}
return [true, ''];
}
$('.datepicker').datepicker({
format: 'dd-mm-yyyy',
todayHighlight: true,
autoclose: true,
weekStart: 1,
startDate: '0d',
language: 'es',
beforeShowDay: daysDisabled
})
just modify your function like this:
function daysDisabled(date) {
for (var i = 0; i < disabledDays.length; i++) {
if (new Date(disabledDays[i]).toString() == date.toString()) {
return false;
}
}
return true;
}
Created Fiddle for you.
Working Fiddle
function initComponent(){
/* Date retrait */
$("#dateRetrait").datepicker({
dateFormat: 'dd-mm-yy',
minDate: new Date(),
beforeShowDay: function(d) {
var dmy = (d.getMonth()+1);
if(d.getMonth()<9)
dmy="0"+dmy;
dmy+= "-";
if(d.getDate()<10) dmy+="0";
dmy+=d.getDate() + "-" + d.getFullYear();
console.log(dmy+' : '+($.inArray(dmy, disbleddates)));
if ($.inArray(dmy, disbleddates) != -1) {
return [false, "","Available"];
} else{
return [true,"","unAvailable"];
}
}
});

Categories

Resources