Default current time in input field.

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
zkarwinkar
Veteran Member
Posts: 32
Joined: 2021-06-12 21:01

Default current time in input field.

Post by zkarwinkar » 2022-06-14 07:36

Hi there ,

i have time select field as exit time , when user open the form i want time field should auto select current time .

Note: Filed is not read-only or appgini auto <%%creationTime%%> . please help!!

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Default current time in input field.

Post by zibrahim » 2022-06-15 23:05

Hi there,
I am using javascript (hooks) to achieve this.

Put the following code in the hooks/TABLENAME-dv.js file (create one if you don't have it yet)

Code: Select all

// populate curent date time for NEW record
$j(function () {
    // check if data (record) exist or not
    if ($j('#TIMEFIELD').val()) return;
    // populate the current date time (using moment.js)
    $j('#TIMEFIELD').val(moment().format('hh:mm:ss A'));
});
* Replace the TABLENAME and TIMEFIELD with yours.
Refresh / clear cache of your browser and the current time should be populated if it is a new record.

Good luck.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply