Re: Re: Use beforeSave() for validation and display error message

Xiaofeng Liu <[email protected]>
Newsgroups gmane.comp.cms.farcry.devel
Message-ID <CACTOi_MQ1zdtyjWWW+V5KFZFHL7xxJZLDriDqFmtgad1eNMKLA@mail.gmail.com>
Hi Chris,

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?

I have the property set to:

<cfproperty ftseq="50" ftFieldSet="Login" type="string" ftLabel="Username"
name="username" ftType="string" ftValidation="required" bLabel="true">

Then I have my validation method as:

<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:

struct BSUCCESS false  STERROR  struct CLASS validation-advice  MESSAGE The
username you have selected is already taken.    VALUE flyingturtle123

However, without abort execution, it still saved the record and not
displaying the validation message anywhere.

Am I missing sth here?




On Mon, Aug 19, 2013 at 6:42 PM, Chris Kent <[email protected]> wrote:

> You would probably be better off using a validate method inside your
> content type. you can set these to validate individual properties. Default
> is to name the function "ftValidate+propertyname", e.g. ftValidateUserID
>
> Look at ftValidateUserID in /core/packages/types/farUser.cfc for an
> example to check for unique userID.
>
> Chris
>
>
> On Monday, 19 August 2013 09:02:46 UTC+1, Xiaofeng Liu wrote:
>>
>> Hi,
>>
>> Within webtop on a custom type, if I'd like to use beforeSave() to check,
>> for example the uniqueness of username before my type record gets saved,
>> how do I bring back that validation message to display on the farcry
>> scaffolded list view or maybe the add/edit view?
>>
>> --
>> Best regards,
>>
>> Xiaofeng
>>
>  --
> You received this message cos you are subscribed to "farcry-dev" Google
> group.
> To post, email: farcry-dev-/[email protected]
> To unsubscribe, email: farcry-dev+unsubscribe-/[email protected]
> For more options: http://groups.google.com/group/farcry-dev
> --------------------------------
> Follow us on Twitter: http://twitter.com/farcry
> ---
> You received this message because you are subscribed to the Google Groups
> "farcry-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to farcry-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Best regards,

Xiaofeng,^_^

-- 
You received this message cos you are subscribed to "farcry-dev" Google group.
To post, email: farcry-dev-/[email protected]
To unsubscribe, email: farcry-dev+unsubscribe-/[email protected]
For more options: http://groups.google.com/group/farcry-dev
--------------------------------
Follow us on Twitter: http://twitter.com/farcry
--- 
You received this message because you are subscribed to the Google Groups "farcry-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to farcry-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/groups/opt_out.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.