Not getting value for dynamically added fields (getting filed name as undefined) and their value in Smart Actions

:warning:This is a template you must use to report issues. :warning:

Feature(s) impacted

We need to add a checkbox based on the dropdown option (considered for option ‘A’). When we select the option ‘A’ from the dropdown then it is working properly. But when we select another option and select option ‘A’ again then the checkbox is again added in forest admin which is expected.
But when we submit the smart action form we are getting undefined parameters while logging the request.body.data.attributes.values object. Also, it displays messages like ‘A value is required for undefined field’

Observed behavior

When we submit the smart action form we are getting an undefined field name for the dynamically added field while logging the request.body.data.attributes.values object. Also, it displays messages like ‘A value is required for undefined field’

Expected behavior

Forest admin smart action should persist the dynamically added fields name and its value.

code for change hooks as below

change: {
          onProductChanged: async (
            /** @type {any} */ { fields, changedField }
          ) => {
            if (changedField.value === 'A') {
              fields.push({
                field: 'checkboxName',
                type: 'Boolean',
                isRequired: true,
              });
            } else {
              fields.splice(
                fields.findIndex((item) => item.field === 'checkboxName'),
                1
              );
            }
            return fields;
          },
        },
      },

Failure Logs

A value is required for an undefined field message in FA prompt.

Context

Please provide in this mandatory section, the relevant information about your configuration:

  • Project name: Curator
  • Team name: Developer
  • Environment name: ALL (Staging, Development, Production)
  • Agent type & version:
  • Package Version: 8.3 (forest-express-sequelize)
  • Express Version: 4.17.1
  • Sequelize Version: 6.6.5
  • Database Dialect: MySql

code for change hooks as below

change: {
          onProductChanged: async (
            /** @type {any} */ { fields, changedField }
          ) => {
            if (changedField.value === 'A') {
              fields.push({
                field: 'checkboxName',
                type: 'Boolean',
                isRequired: true,
              });
            } else {
              fields.splice(
                fields.findIndex((item) => item.field === 'checkboxName'),
                1
              );
            }
            return fields;
          },
        },
      },

Hi @Naresh :wave: I’m trying do reproduce your issue without success.
Can you share with us a little video explaining your flow please? :pray:

@Arnaud_Moncel

Pls find the video here.
Since mp4 is not supported here also there is a size limit.
I m sharing the video in the below link.

Pls find the code below

{
      name: 'Update Data Test',
      type: 'single',
      fields: [
        {
          field: 'Product',
          type: 'Enum',
          enums: ['A', 'B', 'C'],
          isRequired: false,
          hook: 'onProductChanged',
        },
      ],
      hooks: {
        /** @param {*} fields  */
        /** @param {*} request */
        load: async ({ fields }) => {
          return fields;
        },
        change: {
          onProductChanged: (/** @type {any} */ { fields, changedField }) => {
            if (changedField.value === 'A') {
              fields.push({
                field: 'CheckBoxTypes',
                type: 'Boolean',
                isRequired: true,
              });
            } else {
              fields.splice(
                fields.findIndex((item) => item.field === 'CheckBoxTypes'),
                1
              );
            }
            return fields;
          },
        },
      },
    },

Waiting for your revert.

Oooh I see, Thank you, I’m able to reproduce now. You are right there is a bug. I will open a bug report and transfert it to the team.
Thank you again for your feedback :pray:

A fix have been released, can you confirm it fix your the issue? :pray:

1 Like

@Arnaud_Moncel ,

Yes, I can see this bug is resolved now. Thanks for the resolution.

1 Like