Examples / Chat widget
Validation in the chat widget
The chat checks every answer against the form's own rules, and when one does not fit, it explains why in the form's words and asks again.
A chat fills in the same form, so the same rules apply. Every value the UAG takes from a message is checked against the form's validation: required fields, types, minimums and maximums, and patterns, using the form's own error messages. A value the form refuses is not kept; the chat says why and asks again. Nothing invalid can be submitted, because the save goes through the same checks.
This form wants a quantity from 1 to 10, an order code like ABC-1234, and a valid email. The first sample gives an order code without letters and a quantity over 10; the second gives the code in the wrong format and spells out the email. The AI may fix some answers on its own; whatever the form still refuses, the chat asks for again. Correct the answers in the chat.
Turn it on
{
"title": "Example: Validation in the chat widget",
"name": "exampleChatValidation",
"path": "example-chat-validation",
"type": "form",
"display": "form",
"tags": [
"uag"
],
"properties": {
"description": "An order change: the order code, a new quantity, and an email for the confirmation."
},
"components": [
{
"type": "textfield",
"key": "orderCode",
"label": "Order code",
"input": true,
"validate": {
"required": true,
"pattern": "^[A-Z]{3}-\\d{4}$",
"customMessage": "An order code is three capital letters, a dash and four digits, such as ABC-1234."
}
},
{
"type": "number",
"key": "quantity",
"label": "New quantity",
"input": true,
"validate": {
"required": true,
"min": 1,
"max": 10
}
},
{
"type": "email",
"key": "email",
"label": "Email for the confirmation",
"input": true,
"validate": {
"required": true
}
},
{
"type": "button",
"key": "submit",
"label": "Submit",
"action": "submit",
"input": true
}
]
}<link rel="stylesheet" href="https://ai.form.io/uag-js/uag-js.css">
<script src="https://cdn.jsdelivr.net/npm/@formio/js@5.6.1/dist/formio.full.min.js"></script>
<!-- Registers @formio/uag-js with this UAG: forms tagged uag save through it, and get Agent Input and the chat. -->
<script src="https://ai.form.io/uag-js/uag.use.js"></script>
<div id="chat"></div>
<script>
Formio.createChat(document.getElementById('chat'), 'https://uag.form.io/example-chat-validation');
</script>Try it
Start the live examples
The examples call real models. Starting them signs you in as a temporary guest of the examples' project, for every example; what you enter is deleted after a day.
Not supported without a license
This demo needs a license (LICENSE_KEY) that includes the UAG, or a 30-day free trial project on portal.form.io. This deployment has neither: it serves an Open Source project, or its UAG is unlicensed.
The chat widget examples work everywhere, with no license.