Search code examples
alpacajs

Show Current Date Time in field in alpaca automatically


I am using alpaca framework. I have date time type, when I click on it only I can able to select the DateTime, I want this to be filled automatically with current date time when it gets focus or when page loaded.

Any suggestions please.


Solution

  • You can use the "data" object in alpaca config to set the date field default value to current date:

    "data": { "myDateField": new Date() // or you can use moment } }

    You can also set the date in the postRender function like this:

    "postRender": function(control) {
       var date = control.childrenByPropertyId["date"];
       var currentDateTime = moment().format("MM/DD/YYYY HH:mm:ss")
       date.setValue(currentDateTime);
    }
    

    Here's a working fiddle for that.