Generating_Client-Side_Validations

last edited byusericonBob on 01-Mar-2011

Contents

Generating Client-Side Validations

There are two methods that you'll use when generating client-side validations:

The getInitializationScript() Method

Use the getInitializationScript() method to return JavaScript code to set up client-side validations. You only need to generate this script once per page, and can include links for the JavaScript libraries required by the framework.

Arguments

It accepts the following arguments:

Return Value

The getInitializationScript() method returns a string that contains an entire block of JavaScript which can then be inserted into your page. This includes the opening and closing <script> tags.

Examples

<cfset theScript = application.ValidateThis.getInitializationScript() />
<cfhtmlhead text="#theScript#" />

This would ask the framework to generate the JavaScript required to setup the client-side validations. That script is then being loaded into the document via the <cfhtmlhead> tag.

If one does not want the framework to include the <script> tag to load the required libraries, one would call it like this:

<cfset theScript = application.ValidateThis.getInitializationScript(JSIncludes=false) />

The getValidationScript() Method

Use the getValidationScript() method to return JavaScript code for all of the rules that you've defined.

Arguments

It accepts the following arguments:

Return Value

The getValidationScript() method returns a string that contains an entire block of JavaScript which can then be inserted into your page. This includes the opening and closing <script> tags.

Example

<cfset theScript = application.ValidateThis.getValidationScript(objectType='User',context='Register') />
<cfhtmlhead text="#theScript#" />

This would ask the framework to generate the JavaScript required to perform the client-side validations defined in the rules definition file called User.xml for the context of Register. That script is then being loaded into the document via the <cfhtmlhead> tag.

For more information on interacting with the ValidateThis.cfc facade object, see the section on Using the ValidateThis Facade Object.

 
Download in other Formats:
markup Markup | pdf PDF | swf SWF | html HTML | word Word

comments Comments (0)