What version of FarCry are you using?

Chris.

On Wednesday, 28 August 2013 01:58:43 UTC+1, Xiaofeng Liu wrote:
>
> Hi,
>
> As Chris Kent suggested, I actually took a copy of the code in 
> 'ftValidateUserID' method in /core/packages/types/farUser.cfc and adjusted 
> it to do my checking logic for username. The validation method did accept 
> the same arguments as those ones in core and when I dumped the result 
> structure it correctly set the bSuccess to 'false' and the error message 
> accordingly when validation failed. However, after that it ignored the 
> result and still saved the type record with a duplicate username. I have 
> been stuck on this one for quite a while. It looks like something is 
> missing here.
>
> Code is as below:
>
> <cfproperty ftseq="50" ftFieldSet="Login" type="string" ftLabel="Username" 
> name="username" ftType="string" ftValidation="required" bLabel="true">
>
>
>
>  <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>
>
>
>
>
> On Wed, Aug 21, 2013 at 10:11 AM, Blair McKenzie 
> <[email protected]<javascript:>
> > wrote:
>
>> Take a look at the formtool components in core (/packages/formtools). All 
>> validation functions accept the same arguments and should return the same 
>> results as the ones those components have.
>>
>> Blair
>>
>>
>> On Wed, Aug 21, 2013 at 9:18 AM, Xiaofeng Liu 
>> <[email protected]<javascript:>
>> > wrote:
>>
>>> Does anyone have an idea how exactly ftValidate*PropertyName* method 
>>> work?
>>>
>>> I'm just wondering did I miss any steps to get the validation error 
>>> displayed within the webtop or is this a bug in FarCry?
>>>
>>> Any thoughts would be much appreciated.
>>>
>>>
>>>
>>> On Tue, Aug 20, 2013 at 3:02 PM, Xiaofeng Liu 
>>> <[email protected]<javascript:>
>>> > wrote:
>>>
>>>> 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]<javascript:>
>>>> > 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: [email protected] <javascript:>
>>>>> To unsubscribe, email: [email protected] <javascript:>
>>>>> 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 [email protected] <javascript:>.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> Best regards,
>>>>
>>>> Xiaofeng,^_^ 
>>>>
>>>
>>>
>>>
>>> -- 
>>> Best regards,
>>>
>>> Xiaofeng,^_^ 
>>>
>>> -- 
>>> You received this message cos you are subscribed to "farcry-dev" Google 
>>> group.
>>> To post, email: [email protected] <javascript:>
>>> To unsubscribe, email: [email protected] <javascript:>
>>> 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 [email protected] <javascript:>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  -- 
>> You received this message cos you are subscribed to "farcry-dev" Google 
>> group.
>> To post, email: [email protected] <javascript:>
>> To unsubscribe, email: [email protected] <javascript:>
>> 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 [email protected] <javascript:>.
>> 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: [email protected]
To unsubscribe, email: [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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to