Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

Current time option

Avatar

Level 2

Hello,

 

I wanted to ask if there is possibility to have a time field that has two options:

1. The time we enter manually

2. Current time

 

It would be similar to the Date field where we can choose any date or today's date.

 

Thanks for your help!

Magda

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

try this on initialize

 

var event = new Date();

field.rawValue=event.toLocaleTimeString('en-US');

View solution in original post

1 Reply

Avatar

Level 5

I am not sure if you can do it as you suggest but you van have a button next to your time field that set the value of the TimeField to the current time. Like this

MHWinter_0-1651238032999.png

If the TimeField format as HH:MM, the script in the click event of the button would be something like:

var d = new Date();
var ThisHour = d.getHours();
if (ThisHour<10) {ThisHour= "0"+ThisHour}
var ThisMinute = d.getMinutes();
if (ThisMinute <10) {ThisMinute = "0"+ThisMinute }
TimeField1.rawValue = ThisHour + ":" + ThisMinute;

Avatar

Correct answer by
Employee Advisor

try this on initialize

 

var event = new Date();

field.rawValue=event.toLocaleTimeString('en-US');

Avatar

Level 2

The code does work, but I did it on enter, not initialize. I've done it because it shouldn't be visible when the document is open. Also it allows me to type my own time.

 

Thanks!