#How to create a `unique` `string` that can also be `empty` but only `once`

5 messages · Page 1 of 1 (latest)

wary shoal
#

I have a pages collection.
Inside that collection I have a field called slug, which is a String and unique, but I want this field also to be empty to specify which page should be under the / directory, being the landing page.

The problem is that if I specify that field to be nullable causes me to be able to give many pages the NULL value even though that field is specified as unique.

But If I configure that field to be non-nullable the webapp does not allow me to save the item if the field is empty.
My expected behaviour wold be that in this case not filling out that field would make it put an empty string and accept it.
But it is not handled like this.


Suggestion: Make non-nullable strings accept empty values which then would have in terms of a string an empty string?
Or is this intended behaviour?

summer stratusBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

royal lava
#

One way I handle this sort of case is with Flows. It's nice because you can automatically generate a slug if the user does not enter one - or just use the slug they entered.

#

Trigger: Event Hook - items.create in whatever collections have slug field

#

Operations

  • Condition to check if slug field is null
  • IF null: Slugify the title field and save the value in slug field
  • IF not null: do nothing