Created
July 29, 2022 09:26
-
-
Save dislokacia/ea8eec67991c80dcd521fd4d646ffe02 to your computer and use it in GitHub Desktop.
mobile safari datetime for JFB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addZeros(time) { | |
if (time < 10) { | |
time = "0" + time; | |
} | |
return time; | |
} | |
//select the datetime field | |
var dateInput = document.querySelectorAll('.jet-form-builder__field.datetime-field'); | |
//get current date | |
var today = new Date(); | |
var dd = today.getDate() ; | |
var mm = today.getMonth() + 1; //January is 0 so need to add 1 to make it 1! | |
var yyyy = today.getFullYear(); | |
var hr = addZeros(today.getHours()); | |
var min = addZeros(today.getMinutes()); | |
dd = addZeros(dd); | |
mm = addZeros(mm) | |
//paste the current date in the string format in the variable | |
var todayString = yyyy + '-' + mm + '-' + dd+'T'+ hr+':'+min; | |
//trigger the safari for iphones only | |
var d = navigator.userAgent.toLowerCase(), | |
isSafari = (~d.indexOf("safari") && !~d.indexOf("chrome")); | |
//add the current date as the default value | |
if(isSafari) { | |
for (let i=0;i<dateInput.length;i++){ | |
dateInput[i].value= todayString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://prnt.sc/NDxpA6PHGNtt
It will be displayed by default in safari on iphones