Validation

Where the XML Schema provides information about the allowed values of an element or attribute (and therefore of the corresponding field in the template), the field generated will include a JavaScript validate script that verifies that the value is one allowed by the schema declaration. Such information can be provided by way of the data type of the element or attribute and also by restriction facets applied to the base type. Consider the following example:

<xsd:element name="Number"> 
    <xsd:simpleType> 
        <xsd:restriction base="xsd:integer"> 
            <xsd:minInclusive value="4"/> 
            <xsd:maxInclusive value="9"/> 
        </xsd:restriction> 
    </xsd:simpleType> 
</xsd:element>

The mapping will result in a Numeric field named “Number”, which has a validation script that validates that any value is an integer between 4 and 9.

Many of the restriction facets provided by XML Schema provide information that might be used to generate a validation script. This information will only be used to generate validation scripts in cases where the information cannot be mapped directly to a property; for example, mapping the maxLength facet for a string type to <text maxChars=””>.

Numeric type scripts

All numeric types in XML Schema are mapped to a single numeric field. However, the additional restrictions imposed by an XML Schema numeric type are maintained by generating validate scripts to ensure that a number value is the range allowed for the original XML Schema type. An “unsigned byte” type in the XML Schema will generate a numeric field with a script to validate that the value is an unsigned byte value; that is, this is the generated script:

this.rawValue >= 0 && this.rawValue <= 255;

Appropriate range-testing scripts will be generated for the following values:

  • integer

  • positive integer

  • negative integer

  • non-positive integer

  • non-negative integer

  • long, int

  • short

  • byte

  • unsigned long

  • unsigned int

  • unsigned short

  • unsigned byte datatypes

Inclusion/exclusion scripts

When a numeric type specifies min or max inclusion and/or exclusion values, a script will be generated to test that the value entered is within the range defined by these restriction facets. For a field that already has a numeric range script as defined in numeric type scripts in Validation , the script will test the range according to the most restrictive of the datatype range or the inclusion/exclusion range.

length, minLength, and maxLength scripts

An XML Schema string type may specify a length restriction facet or a minLength and/or a maxLength restriction facet. If the schema node is mapped to a text field, values specified for length and minLength restriction facets will be used to generate a validate script to test that the text field length is the value specified by length or is at least the value specified by minLength.

Note that any maxLength facet value will be mapped as maxChars for the text field.

When a string datatype maps to a pop-up list (because of the enumerated values), and length or min/maxLength, values will result in the validate script to check that the value selected in the list has a length that is valid according to the length, minLength, and maxLength facets.

totalDigits/fractionDigits scripts

The totalDigits facet specifies the maximum number of digits that can be used for a decimal or any integer type (that is, decimal, integer, positive integer, negative integer, non-positive integer, non-negative integer, long, int, short, byte, unsigned long, unsigned int, unsigned short, and unsigned byte datatypes). The fractionDigits facet is applicable for the decimal datatype only and specifies the maximum number of fractional digits that may be used.

If totalDigits or fractionDigits are specified for an element or attribute that is mapped to a numeric field, a validate script will be generated to test that the total number of digits and/or number of fraction digits are allowed by the restriction facets.

// Ethnio survey code removed