More info on documentation about event hooks (onBeforeItemUpsert) [Modified title]

Hi,

In the event hooks SDK documentation, can you add the information on when the hook onBeforeItemUpsert is called : before or after the fields validation ? (Event hooks | Documentation — DatoCMS)

Regards

Hey @gdoumenc,

I’ll try to update the docs for that shortly, but to answer your question, it happens before serverside validation, and regardless of clientside validation:


More details:

  • Clientside validation happens on a per-field basis and only on blur (when the user clicks outside or otherwise exits the field)
  • Serverside validation happens when you click “Save”, but:
    • The hook will run first, before anything is sent
    • If you return false from onBeforeItemUpsert(), the validation & save will never happen. The hook intercepts the event and prevents anything from getting sent.
    • If you return true, the hook will still run first, but then validation & saving will proceed normally.

Hope that helps!

I should note that there currently appears to be a bug: If you have a validation error on the form and click Save, but with onBeforeItemUpsert() returning false and thus intercepting the request, the clientside form will think the validation succeeded and clear the validation errors.

I’ve reported that to the devs and will update here (and the documentation too) once it’s resolved.

Sorry about that :slight_smile: