Hi forum,
I'm using Bootstrap studio 5.3 and currently have a form with 23 fields on it. It's a form a user can save progress on and come back to at a later time or date, so there is a "Date Updated" field that is a read only datetime picker.
As of now, I can get the Date Updated field to either (1) set the date and time when the page loads, but can't get it to change after a page change, OR (2) don't set the date and time upon page load, but then set the date and time when the first change happens on the form...however, any subsequent change(s) do not update the field with the new time (I'm assuming date wouldn't update either, but have only tested this with different minutes between form changes).
The setting of this field value seems to be set once and then cannot change after that. I've tried setting date_updated to null and "" before setting it to the returned formattedDateTime, but neither worked as the initial form change datetime is set and does not get reset even if a form change is made a minute (or more) later.
I've also tried with, and without the "new" before calling the formattedDateTime function. Neither works.
How can I get the field to update after each form change?
Screenshot for scenario (1)
Screenshot for scenario (2)
The JS, currently for scenario (2):
which calls the getFormattedDateTime() function in another JS file:
I'm using Bootstrap studio 5.3 and currently have a form with 23 fields on it. It's a form a user can save progress on and come back to at a later time or date, so there is a "Date Updated" field that is a read only datetime picker.
As of now, I can get the Date Updated field to either (1) set the date and time when the page loads, but can't get it to change after a page change, OR (2) don't set the date and time upon page load, but then set the date and time when the first change happens on the form...however, any subsequent change(s) do not update the field with the new time (I'm assuming date wouldn't update either, but have only tested this with different minutes between form changes).
The setting of this field value seems to be set once and then cannot change after that. I've tried setting date_updated to null and "" before setting it to the returned formattedDateTime, but neither worked as the initial form change datetime is set and does not get reset even if a form change is made a minute (or more) later.
I've also tried with, and without the "new" before calling the formattedDateTime function. Neither works.
How can I get the field to update after each form change?
Screenshot for scenario (1)
Screenshot for scenario (2)
The JS, currently for scenario (2):
JavaScript:
//**** Date Updated ****//
//Set Date Updated field to current date time whenever a field is changed.
const form = document.querySelector('form');
form.addEventListener('change', function() {
new getFormattedDateTime();
document.querySelector('#date_updated').value= formattedDateTime;
});
which calls the getFormattedDateTime() function in another JS file:
JavaScript:
//Account for timezones and formate date as mm/dd/yyyy HH:MM AM/PM
const date = new Date(Date.now());
const formattedDateTime = getFormattedDateTime(date);
function getFormattedDateTime(date) {
alert ("getFormattedDateTime Function")
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false,
};
const formatter = new Intl.DateTimeFormat(undefined, options);
const formattedDateTime = formatter.format(date);
return formattedDateTime.replace(
/(\d+)\/(\d+)\/(\d+), (\d+):(\d+)/,
'$3-$1-$2T$4:$5'
);
}