Display problem of default Date value in Smart actions

Hi team,

I have a native SQL field defined in the model:

    paid_at: {
      type: DataTypes.DATE,
      allowNull: true,
    },

In the layout, I chose the Date display widget, and the Date edit widget, with the format “DD/MM/YYYY”

I defined a smart action like this:

    {
      name: 'Mark as paid',
      type: 'single',
      endpoint: 'forest/actions/voucher_bills/single_mark_as_paid',
      fields: [{
        field: 'Paid_at',
        description: 'Select the date at which the bill has been paid',
        type: 'Dateonly',
        isRequired: true,
      }

I have a display problem on the default value of a Dateonly field.

When I initialize the default value with:

values: () => ({ Paid_at: moment().endOf('day') }),

The smart action opens with this display:
image

When I initialize the default value with:

values: () => ({ Paid_at: moment().endOf('day').format('DD/MM/YYYY') }),

Please look result at the video: the date is correctly displayed but month and days are inversed when opening the Dateonly picker (November is becoming August):

When I initialize the default value with:

values: () => ({ Paid_at: moment().endOf('day').format('MM/DD/YYYY') }),

It is correctly initialized, but displayed as an American format (not the French one),
and the displayed is of coursed once again inversed when clicking on the Dateonly picker.

Is it a bug? of else what is the right way to proceed?

Thanks in advance

My setup:

    "database_type": "postgres",
    "liana": "forest-express-sequelize",
    "liana_version": "6.3.13",
    "engine": "nodejs",
    "engine_version": "12.13.1",
    "framework": "express",
    "framework_version": "^4.17.1",
    "orm_version": "5.22.3"

Hi @Louis-Marie,

I’m able to reproduce the exact same issue.

For the first part (Using moment().endOf('day').format('DD/MM/YYYY') instead of moment().endOf('day')), this is due to the fact that widgets settings are currently not supported on smart forms, thus not using the configuration you’ve set on the widget.

For the second part, (Using moment().endOf('day').format('MM/DD/YYYY') instead of moment().endOf('day').format('DD/MM/YYYY')), I can see the date flashing, but it seems to display a correct date on the date picker. (The date sent has not the correct format though, but could easily be parsable on the smart action endpoint side).

My “best” solution would be to remove the values field , and let the user click on the date (Which should be bold, and the widget should display the current month). This is far from perfect, but this should offer you the best solution I can think of for now.

Supporting widget settings in smart actions form is definitely something we have in mind, so I’ll push your subject to our product board.

Hi @jeffladiray

I am sorry, but this is not only a widget problem.
The date picker is present in Forest admin since a long time, and was available in smart forms too since a long time.

This bug is pretty a new recent one, and this is a regression issue.
We need to be able to correctly initialize a default value, and the fact that the calendar is modifying the value in the edit zone when opening it might be the source of this bug.

Could you please consider this problem as a bug and fix it?

Thanks in advance
Best

Oh, my bad, I thought it was related to a newly added smart actions/on the smart action code itself on your end.

What I meant by my previous message was that the Widget Date Picker exists since a long time, but does not use configuration set on the widget settings on your field. In fact, there is currently no way to give configuration to the widgets set in the smart action forms.

If everything was working fine on your smart action and we introduced a recent regression, that’s definitely a bug, but I’ll need to investigate more to find the root of the issue.

Do you have an idea of when you noticed this the first time ? In the meantime, I’ll check on our end if anything recent has been modified on this component, and keep you updated if I’m able to find something.

Hi again,

Ok; I understand this is not linked to widgets.

I am afraid I am not able to determine when the problem occured.
Hope you will be able to find it.

Thanks.

@Louis-Marie, sorry for the delayed response,

After some research, there are no recent changes related to our Date picker widget.

I tried using moment().endOf('day').format('YYYY-MM-DD') which seems to give me expected the result on the forest app (Date seems to be parsed correctly & send the exact same way to the endpoint).


image
image

This is the best solution I can offer right now, since the problem of this seems to be related with the fact that DateOnly fields don’t have enough informations to be parsed on the app side (No timezone + no format specified).

Please note that this issue might only happen in Smart action forms, so let me know if you’ve noticed the issue anywhere else.

Hope that helps, let me know otherwise :pray:

1 Like

Hi @jeffladiray,

Yes, that’s perfect.

This should be added in the smart action documentation, as a way to initialize a default value for a Dateonly type field :wink:

Thank you very much indeed.

Best regards

2 Likes