Custom Elements Documentation

Getting Started

jqxValidator is a HTML Element which enables you to validate users input.

Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.

The first step is to create html page and add links to the javascript files and css dependencies to your project.

The jqxValidator element requires the following files:

<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxvalidator.js"></script>
The next step is to add the html element within the body of the html page.

<jqx-validator settings="elementSettings"></jqx-validator>
The last step is to initialize the element settings:
<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
hintType:"label",animationDuration:0, rules:rules,arrow:false, theme:"light"
}
</script>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxValidator's instance.
<script>
window.onload = function () {
var element = document.querySelector("jqx-validator");
element.hideHint(input1);
}
</script>
To get the result of a function after calling it, you can use the following syntax: To set a property(option), you need to use the property name and value(s) along with the jqxValidator's instance.
window.onload = function() {
document.querySelector("jqx-validator").arrow = true;
}
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".

To get a property(option), you need to use the property name along with the jqxValidator's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-validator").arrow;
}

Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener function can also be used for event binding.

<script>
window.onload = function () {
var element = document.querySelector("jqx-validator");
element.addEventListener("validationError", function(event){
// Your code here
});
}
</script>

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Validator Custom Element</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.light.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxvalidator.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxpasswordinput.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxinput.js"></script>
<style type="text/css">
.text-input {
height: 21px;
width: 200px;
}
.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;
}
</style>
<script>
var rules = [
{ 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: '#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: function (input, commit) {
// call commit with false, when you are doing server validation and you want to display a validation error on this field.
if (document.getElementById("passwordConfirmInput").val() === document.getElementById("passwordInput").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: '#acceptInput', message: 'You have to accept the terms', action: 'change', rule: 'required', position: 'right:0,0' }];
JQXElements.settings["validatorSettings"] = {
hintType:"label",animationDuration:0, rules:rules,arrow:false, theme:"light"
};
function validate() {
document.querySelector('jqx-validator').validate();
return false;
}
</script>
</head>
<body>
<jqx-validator settings="validatorSettings">
<form id="testForm" action="./">
<table class="register-table">
<tr>
<td valign="top">Username:</td>
<td valign="top"><jqx-input type="text" id="userInput" class="text-input"></jqx-input></td>
</tr>
<tr>
<td valign="top">Password:</td>
<td valign="top"><jqx-password-input id="passwordInput" class="text-input"></jqx-password-input></td>
</tr>
<tr>
<td valign="top">Confirm password:</td>
<td valign="top"><jqx-password-input type="password" id="passwordConfirmInput" class="text-input"></jqx-password-input></td>
</tr>
<tr>
<td valign="top">E-mail:</td>
<td valign="top"><jqx-input id="emailInput" placeholder="someone@mail.com" class="text-input"></jqx-input></td>
</tr>
<tr>
<td valign="top" colspan="2" style="padding: 5px;"><jqx-check-box id="acceptInput" style="margin-left: 100px;">I accept terms</jqx-check-box></td>
</tr>
<tr>
<td colspan="2" style="text-align: center;"><jqx-button type="button" onmousedown="validate()" id="sendButton">Send</jqx-button></td>
</tr>
</table>
</form>
</jqx-validator>
</body>
</html>

The result of the above code is: