Validator JAVASCRIPT UI Component API

Validator Javascript API

Class

Validator

Validator plug-in is used to validate form elements.

Selector

smartValidator

Properties

Rrulesrules Click for more details. Property object's options:
  • action:string - A comma-separated list of events to validate the input(s) on.
  • comparisonTarget:{ (inputElement: any, rule: ValidatorRule): any } - A callback function whose result to compare to the input value by the comparisonType in order to show the validation message. Applicable when type is 'compare'.
  • comparisonType:string - An operator to compare the input value by with the result of comparisonTarget in order to show the validation message. Applicable when type is 'compare'.
  • input:string - A valid CSS selector of the input(s) to validate.
  • max:number | Date - The max value of an input when the rule type is 'stringLength' or the max number of characters in the input's value when the rule type is 'range'.
  • message:string - A message to display on focus of the input and in the validation summary if the input's value is not valid.
  • min:number | Date - The min value of an input when the rule type is 'stringLength' or the min number of characters in the input's value when the rule type is 'range'.
  • pattern:RegExp - A regular expression the input's value must match when the rule type is 'pattern'.
  • type:string - The type of validation the rule makes.
  • validationCallback:{ (inputElement: any): boolean } - A callback function to validate the input's value by when the rule's type is 'custom'.
VvalidationSummarySelectorSpecifies a valid CSS selector that identifies the HTML element on the page which will serve as the container for displaying validation error messages. This selector determines where the error messages will appear within the user interface.

Methods

RresetRemoves all error messages from the current context, ensuring that no error notifications are displayed to the user. This action resets the error state, allowing for a clean user experience without residual error indicators.
VvalidateDisplays the drop-down menu, making its list of options visible to the user.

Properties

rules[]

Properties

actionstring

A comma-separated list of events to validate the input(s) on.

Default value

""

Get the action property.

 const validator = document.querySelector('smartValidator');
 let action = validator.rules[0].action;

comparisonTarget{ (inputElement: any, rule: ValidatorRule): any }

A callback function whose result to compare to the input value by the comparisonType in order to show the validation message. Applicable when type is 'compare'.

Default value

Get the comparisonTarget property.

 const validator = document.querySelector('smartValidator');
 let comparisonTarget = validator.rules[0].comparisonTarget;

comparisonTypestring

An operator to compare the input value by with the result of comparisonTarget in order to show the validation message. Applicable when type is 'compare'.

Default value

"=="

Get the comparisonType property.

 const validator = document.querySelector('smartValidator');
 let comparisonType = validator.rules[0].comparisonType;

inputstring

A valid CSS selector of the input(s) to validate.

Default value

""

Get the input property.

 const validator = document.querySelector('smartValidator');
 let input = validator.rules[0].input;

maxnumber | Date

The max value of an input when the rule type is 'stringLength' or the max number of characters in the input's value when the rule type is 'range'.

Default value

Get the max property.

 const validator = document.querySelector('smartValidator');
 let max = validator.rules[0].max;

messagestring

A message to display on focus of the input and in the validation summary if the input's value is not valid.

Default value

""

Get the message property.

 const validator = document.querySelector('smartValidator');
 let message = validator.rules[0].message;

minnumber | Date

The min value of an input when the rule type is 'stringLength' or the min number of characters in the input's value when the rule type is 'range'.

Default value

Get the min property.

 const validator = document.querySelector('smartValidator');
 let min = validator.rules[0].min;

patternRegExp

A regular expression the input's value must match when the rule type is 'pattern'.

Default value

Get the pattern property.

 const validator = document.querySelector('smartValidator');
 let pattern = validator.rules[0].pattern;

type"compare" | "custom" | "email" | "notNumber" | "numeric" | "pattern" | "phone" | "range" | "required" | "startWithLetter" | "stringLength" | "zipCode"

The type of validation the rule makes.

Allowed Values

  • "compare" - The comparison of the input's value and the result of the rule's comparisonTarget by the rule's comparisonType must return true.
  • "custom" - The input's value is validated in the rule's validationCallback function.
  • "email" - The input's value must be a valid email.
  • "notNumber" - The input's value must not be a number.
  • "numeric" - The input's value must be a number.
  • "pattern" - The input's value must match the rugular expression provided by the rule's pattern.
  • "phone" - The input's value must be a valid phone number.
  • "range" - The input's value must be between the values of the rule's min and max.
  • "required" - The input is required to have a non-empty value.
  • "startWithLetter" - The input's value must start with a letter.
  • "stringLength" - The number of characters in the input's value must be between the values of the rule's min and max.
  • "zipCode" - The input's value must be a valid ZIP Code.

Default value

"required"

Get the type property.

 const validator = document.querySelector('smartValidator');
 let type = validator.rules[0].type;

validationCallback{ (inputElement: any): boolean }

A callback function to validate the input's value by when the rule's type is 'custom'.

Default value

Get the validationCallback property.

 const validator = document.querySelector('smartValidator');
 let validationCallback = validator.rules[0].validationCallback;

Example

Set the rules property.

 <smartValidator rules=''></smartValidator>

Set the rules property by using the HTML Element's instance.

 const validator = document.querySelector('smartValidator');
 validator.rules = ;

Get the rules property.

 const validator = document.querySelector('smartValidator');
 let rules = validator.rules;

validationSummarySelectorstring

Specifies a valid CSS selector that identifies the HTML element on the page which will serve as the container for displaying validation error messages. This selector determines where the error messages will appear within the user interface.

Default value

""

Example

Set the validationSummarySelector property.

 <smartValidator validation-summary-selector=''></smartValidator>

Set the validationSummarySelector property by using the HTML Element's instance.

 const validator = document.querySelector('smartValidator');
 validator.validationSummarySelector = '';

Get the validationSummarySelector property.

 const validator = document.querySelector('smartValidator');
 let validationSummarySelector = validator.validationSummarySelector;

Methods

reset(): void

Removes all error messages from the current context, ensuring that no error notifications are displayed to the user. This action resets the error state, allowing for a clean user experience without residual error indicators.


Invoke the reset method.

const validator = document.querySelector('smartValidator');
validator.reset();

validate( result?: Function): void

Displays the drop-down menu, making its list of options visible to the user.

Arguments

result?Function

A callback function to call when validating inputs.


Invoke the validate method.

const validator = document.querySelector('smartValidator');
validator.validate();