Skip to Main Content
Builder.io Ideas
Created by Taylor Miller
Created on Dec 15, 2021

Slug field and custom validations

From customer:


I am trying to add a slug field for content type models, but right now the only option that really works for this is the “text” field type. Unfortunately, text fields on content models do not allow any real validation (outside of “required” and min/max length). We therefore cannot enforce a casing on fields or have an auto-generated slug.

What this means is that I have to guess what case slugs will be at runtime and any casing conventions are derived exclusively from user behavior (rather than being programmatically enforced). It is possible that this could be solved with regex case-insensitive matching, but I am having difficulty getting that to work via your API. Furthermore, it means that this matching paradigm rests exclusively in the API getter logic, which would prove brittle and prone to programmer error.

Could we please get a dedicated slug field type and/or more granular field type validations?

  • Attach files
  • Admin
    Steve Sewell
    Reply
    |
    Dec 15, 2021

    Plugins are usually the best solutions here. A custom editor can be created with any validation logic you like, including uniqueness. A simple example lives here

  • Admin
    Taylor Miller
    Reply
    |
    Dec 15, 2021

    Builder's response:

    great suggestion and we will definitely consider adding in the near term, for now this actually can be accomplished with model validation hooks 1 , it runs on every change and is useful for cases like slugs where you want to ensure the uniqueness of that field.

    For an example of how to use validation hooks check this forum post: How to ensure the uniqueness of a field across all model content 1