Make a string field unique

I cannot recall having to ever enforce this before, but I need to enforce a unique string value for a property of an object. The end content creator is going to create uniquely named coupon that would be best if they cannot accidentally create two instances of (silly content creators). I’ve never had to do that in all the years I’ve been doing FarCry builds. I tried doing a brief search, but does anyone know offhand if that’s something that can forced on a regular 'ol string field?

You can validate any property in a content type using a function that uses the naming convention ftValidatePROPERTYNAME where PROPERTYNAME is the name of your property.

You can see an example of this in core’s farUser.cfc:

Note that the returned value is a result from either the passed() or failed() methods from the formtool component that matches the field.

2 Likes