Inserting formatted date value into a form

Hi,
I need to format a date with moment().format that is inserted through a form. In the form the value is brought in through the User profile data.

Within this Fliplet.User.getCachedSession().then(function(session) I set the variable variable = moment(user[‘LastHireDate’]).format(‘LL’); if I console log this I see the correct format of the date, but I am having trouble inserting this value into the data source/form. I’ve tried using the Fliplet.FormBuilder but the result in the data source is either blank or todays date.

Help please!

Hi Catalina,
when inserting the value via form submit you can use beforeFormSubmit hook, something like:

Fliplet.Hooks.on('beforeFormSubmit', function(data) {
  data['Date picker'] = moment(data['Date picker']).format('LL');
});

Then, the date will be saved and shown in format ‘December 25, 2023’.

But when you load the form, you will need to convert that date field into ISO string, something like:

Fliplet.FormBuilder.get().then(function(form) {
  form.load(function() {
    return Fliplet.DataSources.connectByName('YOUR_DS_NAME').then(function(connection) {
      return connection.findById(Fliplet.Navigate.query.dataSourceEntryId).then(function(record) {
        record.data['YOUR_DATE_COLUMN'] = new Date(record.data['YOUR_DATE_COLUMN']).toISOString();
        return record;
      });
    });
  });
});

Please check our documentation

Hope this help, thanks