You can dynamically populate a validation
script message with a value from a data source. This allows you
to ensure users enter the correct value in the field.
For example, you can display a custom error message when users
enter something in a field that does not match what the script for
a field expects. For example, a numeric field, such as Quantity,
can have a script attached to it that says the number in this field
cannot be greater than 100. If the user enters a number greater
than 100, a custom error message appears.
The schema you connect to could have the following defined for
a validation script:
<form>
<validationScript dp_scriptMessage="message1"/>
</form>
The data file you point to could have the following defined for
script validation:
<form>
<validationScript dp_scriptMessage="DP Script Message - The quantity must be less than or equal to 100."/>
</form>
When you merge the data file with the form design, and you type
a number in the Quantity field that is greater than 100, an error
dialog box appears.
Another example could be to provide custom error messages attached
to a script in another language. The data file you point to could
have the following defined for script validation:
<form>
<validationScript dp_scriptMessage="Entrez un nombre inférieur ou égal à 100."/>
</form>
When you merge the data file with the form design, and you type
a number in the Quantity field that is greater than 100, an error
dialog box in French appears.
Note:
To use non-ASCII text (such as accents) in your
data file, ensure the file is suitably encoded and the encoding
is correctly identified in the XML processing instruction. For example:
<?xml version="1.0" encoding="UTF-8"?>
Before you perform this task, you must ensure the following settings
are in effect:
-
In the Object Library palette, click the Standard category
and drag an object onto the form design.
For example, insert
a Numeric Field object.
-
(Optional) In the Object palette, click the Field tab and
type a caption for the object in the Caption box.
For example,
type
Quantity
.
-
In the Script Editor, select Validate from the Show list.
-
In the Script Editor, select a language from the Language
box.
For example, select JavaScript from the Language box.
-
Type a script for the object.
For example, type this
script for the Quantity field:
this.rawValue <= 100
-
In the Object palette, click the Value tab and then click
the Validation Script Message active label.
-
Select the data connection.
Note:
If you
are not already connected to a data source, Default Data Binding
is the only selection in the Data Connection list.
-
Click the triangle beside the Binding box and select a binding.
For
example, select validation > @dp_scriptMessage.
The
following string appears in the Binding box:
$record.validation.dp_scriptMessage
You could type this string into the Items box instead
of selecting it.
-
Click OK.
-
View the error message by using the Preview PDF tab.
For
example, in the Preview PDF tab, enter a quantity greater than 100.