Resources

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

Home

Forum

Blog

Github

Login

Signup

Made in Builder

Model validation hooks

💡This features is available for Enterprise plans only

Model validation hooks are a powerful feature of Builder that allows you to define custom validation logic for your model's content using JavaScript.

To start, go to your Models page, select the model you want to validate and click Show more options

The click Edit validation hook

A pop-up will appear with this sample code:

The code we write here will have access to these constants:

  • model: The model object being validated
  • contentModel: The entire content object currently loaded in the editor
  • editingVariation: The current content variation being edited

Validation works by returning validation error objects from this code, or returning nothing (undefined) to indicate no errors.

Validation errors are regular JS objects with this shape:

  • level: (required) Indicates the severity of the problem. Possible values are the strings 'warning' or 'error'
  • message: (required) Main error text
  • secondaryMessage: (optional) Additional text about this error.
  • element: (optional) If you can pinpoint the element with the problem, put it here and the editor will highlight it
  • moreInfoUrl: (optional) A URL for external help on the error
  • affectedElements: (optional) If the error is related to several elements, put them all here as an array

You can return a single object to indicate a single error, or you can return an array of these error to indicate several of them.

Chat us for help
Was this article helpful?