Bug on edit multi-select field on workspace

Feature(s) impacted

Observed behavior

In our workspace we visualise field “matieres” of collection “Besoins”, we use an edit button “:writing_hand: :books: Besoin” mode “related fields component” to edit the field directly on the workspace:

when I click on edit besoin, the field “matieres” become like this:
image

this is not correct since it should show each topic :mathematiques, physique,… each one in a row, but it shows all in one row, having this I cant remove one topic, I am obliged to remove all and re-select topics again:

image
in order to get this (the expected view!):
image

However, when I save and click edit again I got this:

image

means got the same issue here.

Expected behavior

I expected to have this view at first:
image

Context

Having workspace and edit fields directly on workspace.

The field on model is defined as array of Enums (list topics “MatieresEnum”) like this:

  • Project name: Clevermate dashboard
  • Environment name: TEST
  • Database type: postgres

Hello @Adel_de_Clevermate,

Thanks for your message :raised_hands:

Great use case here.
Let me try to reproduce on my side and I’ll get back to you shortly.

Cheers.

Hi @Adel_de_Clevermate,

I’ve checked on my side, and it’s working properly.

I think we have a small difference on how the array of enums is defined.

Could you please share how matieres looks in your forestadmin-schema?
Is its type equals to [Enum]?
Is the Enum field well filled with the enum values?

It should look like something like this:

{
      "field": "matieres",
      "type": ["Enum"],
      "defaultValue": [],
      "enums": [
        "Mathématiques",
        "Physique",
        "Aide aux devoirs",
      ],
      "integration": null,
      ...
}

FYI, on my side, this is how my similar field is defined:

matieres: {
        type: DataTypes.ARRAY(
          DataTypes.ENUM({
            values: Object.values(MatieresEnum),
          }),
        ),
      },

Let me know, we’ll figure out together how to fix this!

Cheers.

Hi @anon34731316 ,

Thank you for your response.

I used your same field on model definition:

matieres: {
        type: DataTypes.ARRAY(
          DataTypes.ENUM({
            values: Object.values(MatieresEnum),
          }),
        ),
      },

with MatieresEnum as array of String:

and restarted server,
Here how “matieres” looks on my forestadmin-schema:

{
      "field": "matieres",
      "type": ["Enum"],
      "defaultValue": [],
      "enums": [
        "Mathematiques",
        "Physique",
        "Physique-Chimie",
        "Aide aux devoirs",
        "Francais",
        "Anglais",
        "AGGSP",
        "Stss",
        "TIPE",
        "TOEFL",
        "Tage Mage",
        "Techno",
        "Thermodynamique",
        "eilectricit  ",
        "electrostatique",
        "Autres"
      ],
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": false,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    }

However still got the same behaviour on the workspace.

I appreciate your help, let me know if I missed something.

Thanks

@Adel_de_Clevermate,

Thanks for your prompt response.

Actually, as your MatieresEnum is not defined as Object Keys (const MatieresEnum = { mathematiques: "Mathématiques", physique: "Physique", ... }), you don’t need to declare it the way I did.
So if you get back to your definition and restart your server, your forestadmin-schema should stay the same, is it?

Anyway, the forestadmin-schema you shared looks good to me.
So, could you please share the widget configuration you have for that field (in the Data tab)?


And your workspace component configuration too please?

Thanks!

Hi @anon34731316

Here is the widget configuration of “matieres”:


In the edit setting , I cant find the widget Dropdown (array) as you have.

and cant find also the display widget: Array

Workspace component:

@Adel_de_Clevermate,

Thanks for having checked!
Hum very strange indeed… The detected type is not correct then, it acts as it was an Enum and not an array of Enum :thinking:

Are you still testing on TEST environment? Can you see the changes you make on your agent directly updated on the UI?
Do you confirm you still have this forestadmin-schema?

{
      "field": "matieres",
      "type": ["Enum"],
      "defaultValue": [],
      "enums": [
        "Mathematiques",
        "Physique",
        "Physique-Chimie",
        "Aide aux devoirs",
        "Francais",
        "Anglais",
        "AGGSP",
        "Stss",
        "TIPE",
        "TOEFL",
        "Tage Mage",
        "Techno",
        "Thermodynamique",
        "eilectricit  ",
        "electrostatique",
        "Autres"
      ]
     ...
    }

Did you configure a default value for this field in your model?

What you could try is to remove the field from the model, and add it again to see if it solves the problem (just be aware you’ll lose the UI configuration relative to this field).

Hi @anon34731316

Thank you for your response,

Last time I was not on the right environment!. I redeployed on TEST and here what I got:

Model :

Screen Shot 2023-09-15 at 16.09.23

.forestschema.json

{
      "field": "matieres",
      "type": ["Enum"],
      "defaultValue": [],
      "enums": [
        "Mathématiques",
        "Physique",
        "Physique-Chimie",
        "Aide aux devoirs",
....,
        "Autres"
      ],
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": false,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    },

the field config on Data:


the same config for the fields on workspace.

I noticed also when I clear the field matieres, this happens:
The request PUT is sent with payload having : matieres: [] (looks correct) ,
But the GET Besoin after this returns: matieres: "{}"


And when I viewed on workspace it shown as [{}] like it has an empty objet in the array. expected to be [] empty array.

By consequence, when I click edit I got this:
image

I remove the {} and select some “Matieres” then save to see what happens:
the PUT request:


it sends the payload matieres as array of string (looks correct)
But, like first scenario, the GET returns this:

and field matieres looks :
image
we got back to the issue.

Looks like the issue comes from the difference between PUT and GET data format, {} VS , and array of strings VS object of strings.

Let me know if you got any idea please.

Thanks in advance!

Hello @Adel_de_Clevermate,

Thanks for your answer.

Ok cool, glad to see that working on the right environment is now giving you the right widgets!

Now, you still have some weird behaviour I agree.
The forestadmin-schema definition seems correct. The error seems to come from the GET route indeed.

Did you override the GET route of one or multiple c-besoins?
If you check your matieres field data inside another tool than Forest Admin, does it look correct?

Let’s make some tests and see if it fixes anything:

  • can you try to remove the default value?
  • can you try to upgrade to the latest version of forest-express-sequelize?

We’re going to find the solution! :pray:

Let me know.
Cheers.