Custom validation

It would be great to provide a snippet of javascript or similar that would evaluate input for a given field and return either an all-good or an error message.

We can implement this in two ways:

  • User provides an endpoint, and DatoCMS calls such endpoint passing the payload to validate
  • User provides some JS validation function, and DatoCMS runs it inside a sandbox environment https://www.npmjs.com/package/vm2
1 Like

Hi Stefano! Was this feature implemented? Thanks.

hey @guido.lode not yet.

We tag the feature requests that we release as “launched”. The ones that are currently on our backlog (being in development or soon in dev) ar tagged as “planned”, so that you can track how things are going.

@mat_jack1 Any updates on where this might land on the roadmap? Very interested to get my team on DatoCMS, but without deeper validation abilities we’re a bit hamstrung.

hey @aaronransley sorry but we haven’t decided yet for this feature. It might come in the next 3 to 6 months though, as it’s not very complex, we are just planning to do other wider features before. We’ll publish soon a roadmap for the next three months in our blog!

Hey very long time ago for this feature but what’s the state now? Never?

Sorry @gdoumenc, this is still not a planned feature :frowning:
However, you can now make a custom plugin as a field extension that does validation: https://www.datocms.com/docs/plugin-sdk/field-extensions

And you can intercept/prohibit record saving with a hook:

Hello everyone! We have now the technology to imlpement this efficiently, but we are not sure about the exact use cases that you have in mind. Can you please provide specific examples?

What we have in mind are:

  • conditional fields validations. Right now you can use a plugin to hide/show fields or change their content depending on the selection of another one, but you cannot properly validate that. We will be able to support this use case.
  • multi-field validation. Similarly to the above, you want to validate the content of more than one field together as one field’s content might depend on the previous one to make sense, e.g. Country/State/Province
  • particular validations that are not available, like particular pattern-matchings that are not easily achieved now or that are not supported

What we think NOT to provide:

  • calls to external systems
  • calls to DatoCMS to get other items, so you won’t be able to provide uniqueness checks or checks against other records, e.g. via links

What do you think?

@here - Just tagging all the previous posters here to make sure you saw mat_jack1’s post above:

This is a feature under active development, and your specific examples would be very welcome.

Hi,

Thank you for advancing on this requirement.

Here’s what could be useful and why:

  1. Being able to modify fields, for example completing them based on others (multi-field validation): this seems to be planned.

  2. Calling an external service, as some verification processes can take time and therefore need to be done asynchronously; it would be ideal to enable or disable the ‘publish’ button not during saving, but once the asynchronous processing is complete. This way, publication becomes possible only if the entity is validated. This amounts to adding a new state to an entity: Modified → Saved → Validated(Publishable) → Published.
    In this latter case, data from other entities is used via API calls for validation.

Hope this helps clarify the requirements.