Vue UI Components Documentation
The Vue Validator checks form input against rules and shows a hint next to each invalid field. This guide adds the Vue Validator (jqxValidator) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxvalidator.vue 
In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxValidator from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxvalidator.vue';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
With <script setup>, an imported component is ready to use in the template. jqx.base.css is required; the second file is a theme, selected with the theme attribute.
The Default Functionality demo as a Single-File Component:
<template>
<JqxExpander :width="350" :showArrow="false" :toggleMode="'none'">
<div><h3 style="padding: 0; margin: 0">Register</h3></div>
<div style="padding: 5px">
<JqxValidator ref="myValidator" :rules="rules">
<form id="form" action="./">
<table class="register-table">
<tbody>
<tr>
<td>Username:</td>
<td>
<JqxInput
class="userInput text-input"
:width="195"
:height="22"
></JqxInput>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<JqxPasswordInput
ref="passwordInput"
class="passwordInput text-input"
:width="195"
:height="22"
></JqxPasswordInput>
</td>
</tr>
<tr>
<td>Confirm password:</td>
<td>
<JqxPasswordInput
ref="confirmPasswordInput"
class="passwordConfirmInput text-input"
:width="195"
:height="22"
></JqxPasswordInput>
</td>
</tr>
<tr>
<td>Real name:</td>
<td>
<JqxInput
:width="195"
:height="22"
class="realNameInput text-input"
></JqxInput>
</td>
</tr>
<tr>
<td>Birth date:</td>
<td>
<JqxDateTimeInput
ref="dateTimeInput"
:width="195"
:height="22"
:value="initialDate"
class="birthInput"
></JqxDateTimeInput>
</td>
</tr>
<tr>
<td>E-mail:</td>
<td>
<JqxInput
:placeHolder="'someone@mail.com'"
class="emailInput text-input"
:width="195"
:height="22"
></JqxInput>
</td>
</tr>
<tr>
<td>SSN:</td>
<td>
<JqxMaskedInput
:width="195"
:height="22"
:mask="'###-##-####'"
class="ssnInput"
></JqxMaskedInput>
</td>
</tr>
<tr>
<td>Phone:</td>
<td>
<JqxMaskedInput
:width="195"
:height="22"
:mask="'(###)###-####'"
class="phoneInput"
></JqxMaskedInput>
</td>
</tr>
<tr>
<td>Zip code:</td>
<td>
<JqxMaskedInput
:width="195"
:height="22"
:mask="'###-##-####'"
class="zipInput"
></JqxMaskedInput>
</td>
</tr>
<tr>
<td
colspan="2"
style="
padding-left: 100px;
padding-top: 10px;
padding-bottom: 10px;
"
>
<JqxCheckBox :width="130" class="acceptCheckBox"
>I accept terms</JqxCheckBox
>
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 20px">
<JqxButton
@click="sendButton()"
style="text-align: center; margin-left: 8em"
:width="60"
:height="25"
>
Send
</JqxButton>
</td>
</tr>
</tbody>
</table>
</form>
</JqxValidator>
</div>
</JqxExpander>
</template>
<script setup>
import { ref } from 'vue';
import JqxExpander from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxexpander.vue';
import JqxValidator from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxvalidator.vue';
import JqxInput from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxinput.vue';
import JqxPasswordInput from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxpasswordinput.vue';
import JqxDateTimeInput from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdatetimeinput.vue';
import JqxMaskedInput from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxmaskedinput.vue';
import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.vue';
import JqxButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxbuttons.vue';
const dateTimeInput = ref(null);
const passwordInput = ref(null);
const confirmPasswordInput = ref(null);
const myValidator = ref(null);
const initialDate = ref(new Date(2023, 8, 1));
const rules = ref([
{
input: '.userInput',
message: 'Username is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.userInput',
message: 'Your username must be between 3 and 12 characters!',
action: 'keyup, blur',
rule: 'length=3,12'
},
{
input: '.realNameInput',
message: 'Real Name is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.realNameInput',
message: 'Your real name must contain only letters!',
action: 'keyup',
rule: 'notNumber'
},
{
input: '.realNameInput',
message: 'Your real name must be between 3 and 12 characters!',
action: 'keyup',
rule: 'length=2,12'
},
{
input: '.birthInput',
message: 'Your birth date must be between 1/1/1906 and 12/31/2025.',
action: 'valueChanged',
rule: (input, commit) => {
let date = dateTimeInput.value.value;
let result = date.getFullYear() >= 1906 && date.getFullYear() <= 2026;
return result;
}
},
{
input: '.passwordInput',
message: 'Password is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.passwordInput',
message: 'Your password must be between 4 and 12 characters!',
action: 'keyup, blur',
rule: 'length=4,12'
},
{
input: '.passwordConfirmInput',
message: 'Password is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.passwordConfirmInput',
message: "Passwords doesn't match!",
action: 'keyup, focus',
rule: (input, commit) => {
if (passwordInput.value.val() === confirmPasswordInput.value.val()) {
return true;
}
return false;
}
},
{
input: '.emailInput',
message: 'E-mail is required!',
action: 'keyup, blur',
rule: 'required'
},
{ input: '.emailInput', message: 'Invalid e-mail!', action: 'keyup', rule: 'email' },
{ input: '.ssnInput', message: 'Invalid SSN!', action: 'valuechanged, blur', rule: 'ssn' },
{
input: '.phoneInput',
message: 'Invalid phone number!',
action: 'valuechanged, blur',
rule: 'phone'
},
{
input: '.zipInput',
message: 'Invalid zip code!',
action: 'valuechanged, blur',
rule: 'zipCode'
},
{
input: '.acceptCheckBox',
message: 'You have to accept the terms',
action: 'change',
rule: 'required',
position: 'right:217,0'
}
]);
function sendButton() {
myValidator.value.validate(document.getElementById('form'));
}
</script>
<style>
html,
body {
width: 100vw;
height: 100vh;
padding: 0;
margin: 0;
}
.register-table {
margin-top: 10px;
margin-bottom: 10px;
}
.register-table td,
.register-table tr {
margin: 0px;
padding: 2px;
border-spacing: 0px;
border-collapse: collapse;
font-family: Verdana;
font-size: 12px;
}
h3 {
display: inline-block;
margin: 0px;
padding: 0px;
}
</style>Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, validationError: This is triggered when the form is validated with some errors.
<script setup>
function onValidationError(event) {
console.log(event.args);
}
</script>
<template>
<JqxValidator @validationError="onValidationError" />
</template>
Call methods through a template ref. For example, hideHint: Hide all hints for a specific input.
<script setup>
import { ref, onMounted } from 'vue';
const myValidator = ref(null);
onMounted(() => {
myValidator.value.hideHint('#userInput');
});
</script>
<template>
<JqxValidator ref="myValidator" />
</template>
Every component also has setOptions({ … }) and getOptions('name').