Checks the formatted items in the form and returns the number of items whose format is not valid. You can also reduce the scope of the validation check by checking specific pages or individual items. Furthermore, you can set the function to create a list of the items that are not valid.
checkValidFormats(listReference, optionName, validationReference,
referenceType, schema)
Parameter | Type | Description |
---|---|---|
listReference | Reference string | Optional. A reference
to an option that will contain the list of items that are not valid. For example, if you called the function from a label item, you might create the following custom option: <label sid="numberInvalid"> <custom:list>In this case, you would use the following reference: custom:listThe function creates the option if it does not already exist. The function then populates the option with a list of references to the items that are not valid. For example, if two fields were not valid you would get a list like this:
If this parameter is not specified in the call, the function still validates all form items but does not create a list of references to invalid items. |
optionName | String | optional. Sets the tag
that is used to store each item in the list of not valid items. This
parameter is useful when you need to set a particular namespace for
the list. For example, if you store your list in a custom:list option,
you might set the following tag: custom:invalidref
Doing this ensures that the list is stored in the same namespace as the containing element. Default: xfdl:option |
validation Reference | Reference string | optional. A reference to the section of the form that you want to validate. For example, "PAGE1.FIELD1". If " " or an empty string is used, this function checks the current object. |
referenceType | String | optional. Defines the type of reference used by the validation reference parameter. Valid settings are form, page, or item. |
schema | Reference string | optional. Defines the format of the reference. If not specified, the default of XFDL is applied. |
Returns the number of items that failed the validity check. If all items are valid, the function returns 0.
The following sample form shows how you can use the checkValidFormats function to specify custom behaviors when a form with values that are not valid is submitted. Note that the format of FIELD2 is checked even if it is not currently displayed.
<?xml version="1.0"?>
<XFDL xmlns="http://www.ibm.com/xmlns/prod/XFDL/8.0"
xmlns:xfdl="http://www.ibm.com/xmlns/prod/XFDL/8.0"
xmlns:custom="http://www.ibm.com/xmlns/prod/XFDL/Custom">
<globalpage sid="global">
<global sid="global"></global>
</globalpage>
<page sid="PAGE1">
<global sid="global"></global>
<field sid="FIELD1">
<format>
<datatype>date</datatype>
<constraints>
<mandatory>on</mandatory>
</constraints>
</format>
</field>
<field sid="FIELD2">
<value>4.00</value>
<format>
<datatype>dollar</datatype>
<constraints>
<mandatory>on</mandatory>
<applyifinvisible>on</applyifinvisible>
</constraints>
</format>
</field>
<button sid="BUTTON1">
<value>Submit</value>
<type>done</type>
<url>http://localhost/cgi-bin/test.pl</url>
<custom:checkIfValid xfdl:compute=
"toggle(BUTTON1.activated, 'off', 'on') == '1' ? 

(checkValidFormats('custom:brokenOptions', 

'custom:invalidref') != '0' ? 

set('BUTTON1.activated', 'off') + 

viewer.messageBox('Unable to send because at ' 

+. 'least ' +. custom:brokenOptions[0] +. 

'item is invalid.') : '') : ''"></custom:checkIfValid>
</button>
</page>
</XFDL>
The format option for FIELD1 specifies that this item must contain a date and cannot be blank. If a user submits the form without correctly completing this field, the checkValidFormats function prevents the submission. Instead, the function creates a new option called brokenOptions:
<custom:brokenOptions>
<custom:invalidref>PAGE1.FIELD1</custom:invalidref>
</custom:brokenOptions>
The remaining code uses the information in brokenOptions to display a context-sensitive message to the user.