Datetime picker do not update properly

Hi,

I use multiple fields with datetime pickers in a smartAction form and my problem is, when the value is pre-filled by a load() hook, I have to input my new date in the widget twice to modify the value.

If I modify the date only once, the value is not updated.

The fields are created in the load() hook.
Everything seems to work fine if the field is empty when the form is loaded.

Is that a known bug ?

Hello @Cobs,

For us to be able to give you the best possible support, it would be really helpful if you could fill out the template.

## Context

<!-- Please provide in this **mandatory section**, the relevant information about your configuration: -->
- Project name: ...
- Team name: ...
- Environment name: ...
- Agent technology: (nodejs, php, rails, python)
- Agent (forest package) name & version: ...
- Database type: ...
- Recent changes made on your end if any: ... 

On top of that could you share with us the way you have defined your load() hook ?

Best regards,

Thanks for the reply, here is the filled template.

- Project name: Mytraiteur
- Team name: MyCompany
- Environment name: Developpement
- Agent technology: Node
- Agent (forest package) name & version: forest-express-sequelize@9.3.9
- Database type: Mysql

Could you please share your implementation ?

I have not been able to reproduce, my date field is properly updated at the first input and the value is correct when executing the action.

You can reproduce the bug with this action.
Open the form then try to change the time (not the day)

{
  name = "My Action"

  type = 'single'

  fields = [{
    field: `Do not remove`,
    description: `Forest wont display the form if the fields array is empty before load`,
    type: 'String',
    isReadOnly: true
  }]

  hooks = {
    load: () => {
      return [
        {
          field: `Date`,
          value: new Date('2024-12-01'),
          type: 'Date',
        },
      ]
    }
  }
}

Thanks for sharing your usecase, I have indeed been able to reproduce the issue and a fix is already under review, I will post a message once its released.

The issue only appears when the date is not a complete datetime so you can fix it in the meantime with an implementation similar to the next one:

{
    name: 'Charge credit card',
    type: 'single',
    fields: [{
      field: 'amount',
      isRequired: true,
      type: 'Number'
      }, {
      field: 'charge date',
      isRequired: true,
      type: 'Date'
    }],
    hooks: {
      load: async ({ fields, request }) => {
        const dateField = fields.find(field => field.field === 'charge date');

        dateField.value = new Date();

        return fields;
      },
    },
  }

I also noticed that you’re using a temporary field to display the form, it is possible like in my exemple to update existing fields with the load hook so you can keep your configuration clearer :slight_smile:

The fix on the Datetime picker widget is now live in production, please refresh your browser to benefit from the fix.

hum… I can’t programmatically choose the date in the field and prevent the bug, do I ?

Oh yes, I know you can update existing fields.
I simplified my action to have the minimum code you can copy/paste to reproduce.
In the real thing, I return between 1 to N fields depending on values in the database.

It looks good to me.
Many thanks.

1 Like