Home App Docs Blog Github

Slug field and custom validations


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).

You can see how this can lead to problems in your own blog:

https://www.builder.io/c/docs/how-builder-works ← valid page
https://www.builder.io/c/docs/How-builder-works ← invalid page.

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?

Thanks @Dustin-gf, great suggestion and we will definitely consider adding in the near term, for now this actually can be accomplished with model validation hooks , 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

Good morning, @aziz. That looks like a great stop-gap! I appreciate the link.

That article is not in the docs’ Table of Contents on the left-hand side. If you hadn’t linked it, I doubt that I would have discovered it through search alone. Is there a good, central location to peruse all of the current documentation, including features only available to Enterprise plans?

@Dustin-gf , very good point about the doc not being in the left hand side nav. We are working on a project to hopefully have MUCH better organized docs in the future so things like that are easier to find. For now, I would suggest relying on the search bar on our docs page, since that pulls results from our docs, our forum, and our blog posts.

And please keep the feedback coming! We appreciate it.