Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Today's date as default date

Avatar

Level 2

Hello,

I just want to set the default date of a date field as today's date, what do I need to enter in the default value field of the object menu?

Thanks!

Dave

7 Replies

Avatar

Former Community Member

If you look in the Custom LIbrary there is a Current Date object. Just dragh that onto your form and it will populate with today's date when you render the form.

Paul

Avatar

Level 2

I don't see what you are talking about.  I only have a date/hour field that I can drag to the form, but nothing concerning Current Date?

Also, I would like a field that shows today's date as a default value, but that the user can change if he wants to...

Thanks for your help!

Dave

Avatar

Level 2

Thanks for the screen shot, I had forgotten about the custom objects!

Is there a way that I can have this default date, but that the user can change it?  In the object panel of my date/hour field, there is a place where I can enter a default value.  Is there some kind of script I can enter that will make today's date the default value instead of a precise date?

Thanks again!

Avatar

Former Community Member

Instead I would suggest that you use code on the Doc Ready event to do this:

if

(this.rawValue == null) then

     $.rawValue

= num2date(date(), DateFmt(1))

endif

Remember that this is FormCalc code so set the language in the script editor accordingly. The if condition is used so that if you save the form and open it again the values are not over written with the current date.

Hope that helps

Paul

Avatar

Level 2

I just realized that with the ES 2 version of LCD, it's fairly easy to do this with the Action Builder!

Thank you very much for your help!

Avatar

Level 1

Unbelievable - another idiot that doesn't read the question and jumps straight in with the wrong answer. The question is 'set today's date as the DEFAULT date' idiot - not the committed date.