keystone icon indicating copy to clipboard operation
keystone copied to clipboard

validateInput list hook not called when a list item is modified indirectly by clearing a relationship field

Open remygendron opened this issue 3 years ago • 0 comments

User list has a many: true relationship field to Message list. Message list has a many: false relationship field to User.

(hence the foreign key to User is defined on Message, this is a 1-to-many relationship)

I have a validateInput hook on the message list to require the relationship to user to be set:

hooks: {
    validateInput: ({ operation, resolvedData, addValidationError }) => {
      if (
        (operation === 'create' && resolvedData.from === undefined) ||
        (operation === 'update' && resolvedData.from !== undefined && resolvedData.from.disconnect)
      ) {
        addValidationError("message.from.not.null:L''auteur du message est requis.");
      }
      ...

When I create a message, I get an error if the from field is left empty.

When I go into the admin ui on the User item, I can delete a relationship to one message and save the user without error. I can thereafter go to the associated message detail screen and the from field is empty.

I expect that the validateInput hook be triggered for a list when a relationship to an entry from that list is modified by an update operation on the list on the other side of the relationship.

Using latest KS6:

  "@keystone-6/auth": "^1.0.2",
  "@keystone-6/core": "^1.0.1",
  "@keystone-6/fields-document": "^1.0.1",

remygendron avatar Feb 23 '22 02:02 remygendron