Skip to content

Instantly share code, notes, and snippets.

@dislokacia
Created July 29, 2022 09:26
Show Gist options
  • Save dislokacia/ea8eec67991c80dcd521fd4d646ffe02 to your computer and use it in GitHub Desktop.
Save dislokacia/ea8eec67991c80dcd521fd4d646ffe02 to your computer and use it in GitHub Desktop.
mobile safari datetime for JFB
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;
}
}
@dislokacia
Copy link
Author

https://prnt.sc/NDxpA6PHGNtt
It will be displayed by default in safari on iphones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment