You can use widgets to validate input in XForms elements. The Simple Forms Validator widget checks if the value in a single XForms field is valid. The Multiple Forms Validator checks that the values in multiple fields, taken together, meet some specified constraints. Refer to 5.4. Validating multiple forms for more information.
You can use widgets to validate input in XForms elements. The Simple Forms Validator widget checks if the value in a single XForms field is valid. The Multiple Forms Validator checks that the values in multiple fields, taken together, meet some specified constraints. Refer to 5.4. Validating multiple forms for more information.
This time the form data model specifies two items: 'name' and 'PIN'.
Create a simplevalidator.xdime file
<xforms:model>
<xforms:instance>
<si:instance>
<si:item name="name"/>
<si:item name="pin"/>
</si:instance>
</instance>
<xforms:submission id="submit" action="http://example.com/response/pin.xdime"/>
</xforms:model>
Ensure that you refer to the validator.mthm in a link element. The validation rules are defined by the mcs-input-format property specified in the theme, and so are the message styles. See 2.8. Additional themes for more information.
Enter 'Simple Form Validator' as the title value in the template:binding element
<template:complexValue>Please enter a name and PIN
<div style="mcs-layout: 'layouts/validator.mlyt';">
...
</div>
</template:complexValue>
<xforms:input ref="name" id="name">
<xforms:label>Name</xforms:label>
<widget:validate message-area="formMessage1">
...
</widget:validate>
</xforms:input>
<span id="formMessage1"/>
...
<widget:message class="error" type="empty">The name cannot
be empty!</widget:message>
<widget:message class="error" type="invalid">The name must be at least 4
characters and start with an uppercase character!</widget:message>
Finally, add the XML representing the PIN input. Your file, simplevalidator.xdime, should look like this.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2"
xmlns:mcs="http://www.volantis.com/xmlns/2006/01/xdime/mcs"
xmlns:template="http://www.volantis.com/xmlns/marlin-template"
xmlns:widget="http://www.volantis.com/xmlns/2006/05/widget"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:si="http://www.volantis.com/xmlns/2006/01/xdime2/si"
xmlns:urid="http://www.volantis.com/xmlns/marlin-uri-driver">
<head>
<title>Simple Form Validator</title>
<link rel="mcs:theme" href="/themes/main.mthm"/>
<link rel="mcs:theme" href="/themes/validator.mthm"/>
<link rel="mcs:layout" href="/layouts/main.mlyt"/>
<xforms:model>
<xforms:instance>
<si:instance>
<si:item name="name"/>
<si:item name="pin"/>
</si:instance>
</xforms:instance>
<xforms:submission id="submit" action="http://example.com/response/pin.xdime"/>
</xforms:model>
</head>
<body>
<template:apply href="templates/demo-main.xdtpl">
<template:binding name="title" value="Simple Form Validator"/>
<template:binding name="content">
<template:complexValue>Please enter a name and PIN
<div style="mcs-layout: 'layouts/validator.mlyt';">
<xforms:input ref="name" id="name" style="mcs-container: 'input1'">
<xforms:label style="mcs-container:'text1'">Name</xforms:label>
<widget:validate message-area="formMessage1">
<widget:message class="error" type="empty">
The name cannot be empty!</widget:message>
<widget:message class="error" type="invalid">The name must be at least 4
characters and start with an uppercase character!</widget:message>
</widget:validate>
</xforms:input>
<span id="formMessage1" style="mcs-container: 'message1'"/>
<xforms:input ref="pin" id="pin" style="mcs-container: 'input2'">
<xforms:label style="mcs-container: 'text2'">PIN</xforms:label>
<widget:validate message-area="formMessage2">
<widget:message class="error" type="empty">PIN cannot
be empty!</widget:message>
<widget:message class="error" type="invalid">PIN must consist of 6
digits!</widget:message>
</widget:validate>
</xforms:input>
<span id="formMessage2" style="mcs-container: 'message2'"/>
</div>
</template:complexValue>
</template:binding>
</template:apply>
</body>
</html>
Name | Purpose |
---|---|
div | A section used to add extra structure to documents. Style sheets can be used to control the presentation. |
si:instance | Container for data items used to supply initial values for forms controls, or to provide additional data to be submitted with the form. |
si:item | Defines an item of instance data that is required if a form control needs to be initialized, or when data not associated with a form control needs to be provided during form submission. |
span | Inline element used to set a style. |
widget:message | Message displayed when particular type of validation error occurs. This element is used by the Simple Validator widget. It should not be specified for a Multiple Forms Validator widget because a server side process is responsible for displaying error messages. |
widget:validate | Enables form validation in both the Simple and Multiple Forms Validator widgets. |
xforms:input | A form control for text input. |
xforms:instance | Optional element that contains instance data associated with the model element. It is used to supply initial values for forms controls, or to provide additional data to be submitted with the form. |
xforms:label | Provides a descriptive label for forms controls. |
xforms:model | Represents a form definition, used as a container for elements associated with its submission. |
xforms:submission | Defines the information to submit, where it should be sent, and how to send it. |
Core attributes | Attributes that are common to XDIME 2 elements. |