Remove field validation in @forestadmin/agent 1.0.0

I want to create records in Forest Admin for a table “Account”.
The Account table has a “id” primary that is an UUID V4 generated by my backend, not the database.

In forest admin, I found a way to generate the id in the backend like this:

  customizeCollection('Account', (collection: Collection<Schema, 'Account'>) => {
    collection.replaceFieldWriting('id', () => {
      return { id: uuid() };
    });
  });

However, the id is still required in the Forest Admin interface when creating new records.

How can I hide this field in the form to create new Accounts?

Observed behavior

I cannot remove validation on a field

Expected behavior

I would expect to be able to remove a field validation

Context

  • Project name: Capsule
  • Team name: Founders
  • Environment name: production
  • Agent type & version: @forestadmin/agent 1.0.0
  • Recent changes made on your end if any: none

Other info

My ORM (Prisma) create primary keys that look like this in the database

CREATE TABLE public."Workspace"
(
    id text COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT "Workspace_pkey" PRIMARY KEY (id),
)

Hello @leonard_henriquez ,

Thank you for your feedback! We are testing your useCase on our side, I will come back to you as soon as we have more information :pray:

Kind regards,

Florian


Hi @leonard_henriquez ,

For you need, you can try to activate Read-only for your field. It should be the answer to your need.
To access to this screen, go to Edit layout and go the Settings of your collection, then on the Fields tab and click on the id field.

Let me know if suit your needs.

Best,

Shohan

Hi,
Thank you for the help but unfortunately, it doesn’t remove the validation…

Hi @leonard_henriquez

The replaceFieldWriting method is called only when the field is modified (which is not the case here), so it’s not the customization method that you would need in that case.

Besides the handler runs for updates as well, you only want creation.

Can you try this instead?

collection.addHook('Before', 'Create', context => {
  context.data.forEach(datum => { datum.id = uuid() })
})
1 Like

Thank you @anon39940173 it helped !

So the solution is remove a validation on a field is to:

  • Add a before hook to populate the value
  • AND turn this field into a read only field in Forest interface

:+1:

You can also hide the “id” field in the creation form (activating the layout editor while the creation form is opened), it will also automatically remove the form validation.

About the replaceFieldWriting we will adapt its implementation to make it work as you expected for the record creation use case.

1 Like