Thanks for pointing to the use of form tools validation methods. However, how would I get the error message displayed on my custom type edit form?
<cffunction name="ftValidateUsername" access="public" output="true" returntype="struct" hint="This will return a struct with bSuccess and stError">
<cfargument name="objectid" required="true" type="string" hint="The objectid of the object that this field is part of.">
<cfargument name="typename" required="true" type="string" hint="The name of the type that this field is part of.">
<cfargument name="stFieldPost" required="true" type="struct" hint="The fields that are relevent to this field type.">
<cfargument name="stMetadata" required="true" type="struct" hint="This is the metadata that is either setup as part of the type.cfc or overridden when calling ft:object by using the stMetadata argument.">
<cfset var stResult = structNew()>
<cfset var qDuplicate = queryNew("blah")>
<cfset stResult = createObject("component", application.formtools["field"].packagePath).passed(value=stFieldPost.Value) />
<!--- --------------------------- --->
<!--- Perform any validation here --->
<!--- --------------------------- --->
<cfquery datasource="#application.dsn#" name="qDuplicate">
SELECT objectid from userProfile
WHERE upper(username) = '#ucase(stFieldPost.Value)#'
</cfquery>
<cfif qDuplicate.RecordCount>
<!--- DUPLICATE USERNAME --->
<cfset stResult = createObject("component", application.formtools["field"].packagePath).failed(value="#arguments.stFieldPost.value#", message="The username you have selected is already taken.") />
<!--- <cfdump var="#stResult#"><cfabort> --->
</cfif>
<!--- ----------------- --->
<!--- Return the Result --->
<!--- ----------------- --->
<cfreturn stResult>
</cffunction>
If I dump out the stResult, I can see ftValidateUsername is invoked and it correctly detected the duplicates and set the error message:
However, without abort execution, it still saved the record and not displaying the validation message anywhere.