Form Field Validation
There are several ways to control the user's input, restrict the type of characters, the maximal length or match the input values to a certain pattern to ensure only valid and correct values are stored.
HTML5 Field Validation
​HTML5 already provides client side input validation based on the input type, this function can be used by assigning the correct type to the form control TextField.
TextField
​-
TextField with no validation:
<input id="text1" data-hf-control="TextField" type="text" />
-
TextField with type number:
<input id="number1" data-hf-control="TextField" type="number" />
-
TextField with type telephone:
<input id="tel1" data-hf-control="TextField" type="tel" />
-
TextField with type e-mail:
<input id="email1" data-hf-control="TextField" type="email" />
-
TextField with type date:
<input id="date1" data-hf-control="TextField" type="date" />
-
TextField with type time:
<input id="time1" data-hf-control="TextField" type="time" />
These validations are very limited and restricted to single line input elements and often do not meet the necessities of the desired input validation. Therefore we provide extended options for a better client-side input validation.
Extra Validation
​Besides the already implemented data-hf-option "required: true"
, which checks if a field has been filled in, you can define more individual validation rules by adding the data-hf-option "validator"
or by defining a custom validation function.
ComboBox​
The ComboBox
only allows to select values from the configured data source. The option anytext: true
allows to enter free text.
<div
id="combobox1"
data-hf-control="ComboBox"
data-hf-options="{
required: true,
anytext: false,
dataSource: [
{ name: 'Bauer, F', code: 'Bauer, F' },
{ name: 'Gruber, P', code: 'Gruber, P' },
{ name: 'Lanner, G', code: 'Lanner, G' },
{ name: 'Simon, R', code: '3521' },
{ name: 'Herbert, W', code: '123456789012' }
],
dataTextField: 'name',
dataValueField: 'code',
validator: {
errorText: 'Only inputs from the dropdown are allowed.'
}
}"
></div>
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.errorHTML​
errorHTML: 'Only <strong>inputs from the dropdown</strong> are allowed.'
string
validator.errorText​
errorText: 'Only inputs from the dropdown are allowed.'
string
validator.maxlength​
maxlength: 10
number
errorText / errorHTML interface
​interface IErrorMessages {
anytext?: string;
maxlength?: string;
[custom: string]: string;
default: string;
}
DataControl​
<div
id="test_data_control"
data-hf-control="DataControl"
data-hf-options="{
validator: {
jsonSchema: {
type: 'array',
items: {
type: 'object',
properties: {
test_data_control: {
type: 'string',
minLength: 1,
maxLength: 10
}
}
}
}
}
}"
></div>
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.jsonSchema​
jsonSchema: {}
jsonschema
DatePicker​
<div
id="birthday"
data-hf-control="DatePicker"
data-hf-options="{
required: true,
displayValueFormat: 'dd.MM.yyyy',
max: 'now',
min: '1965-05-14',
parseFormats: [ 'dd.MM.yyyy', 'ddMMyyyy', 'dd/MM/yyyy', 'dd-MM-yyyy' ],
validator: {
errorText: 'Please enter a valid date.'
}
}"
></div>
max​
max: 'now'
string
min​
min: '1965-05-14'
string
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.errorHTML​
errorHTML: 'Please enter a <strong>valid date</strong>.'
string
validator.errorText​
errorText: 'Please enter a valid date.'
string
errorText / errorHTML interface
​interface IErrorMessages {
max?: string;
min?: string;
[custom: string]: string;
default: string;
}
DropDownList​
The DropDownList
only allows to select values from the configured data source.
<div
id="dropdownlist1"
data-hf-control="DropDownList"
data-hf-options="{
required: true,
dataSource: [
{ name: 'Bauer, F', code: 'Bauer, F' },
{ name: 'Gruber, P', code: 'Gruber, P' },
{ name: 'Lanner, G', code: 'Lanner, G' },
{ name: 'Simon, R', code: '3521' },
{ name: 'Herbert, W', code: '123456789012' }
],
dataTextField: 'name',
dataValueField: 'code',
validator: {
errorText: 'Only inputs from the dropdown are allowed.'
}
}"
></div>
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.errorHTML​
errorHTML: 'Only <strong>inputs from the dropdown</strong> are allowed.'
string
validator.errorText​
errorText: 'Only inputs from the dropdown are allowed.'
string
errorText / errorHTML interface
​interface IErrorMessages {
[custom: string]: string;
default: string;
}
NumericField​
<div
id="temperatur"
data-hf-control="NumericField"
data-hf-options="{
step: 0.1,
min: 20,
max: 45,
placeholder: '°C',
decimals: 1,
format: '0.0°',
startValue: 36
}"
></div>
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.errorHTML​
errorHTML: 'Only <strong>inputs from the dropdown</strong> are allowed.'
string
validator.errorText​
errorText: 'Only inputs from the dropdown are allowed.'
string
errorText / errorHTML interface
​interface IErrorMessages {
min?: string;
max?: string;
[custom: string]: string;
default: string;
}
SelectBox​
Field value must be one of the option values if selected
<select id="select1" data-hf-control="SelectBox">
<option value="value1">value 1</option>
<option value="value2">value 2</option>
...
</select>
validator.custom​
custom: 'HFFormDefinition.Namespace.validate'
function
(field: object, value: string) => boolean
validator.errorHTML​
errorHTML: 'Only <strong>inputs from the dropdown</strong> are allowed.'
string
validator.errorText​
errorText: 'Only inputs from the dropdown are allowed.'
string
errorText / errorHTML interface
​interface IErrorMessages {
[custom: string]: string;
default: string;
}
TextField​
The TextField
can be extended by the option validator
.
This overrules the HTML5 validation.
<input
id="textfield1"
type="(text|number|tel|email|date|time)"
data-hf-control="TextField"
data-hf-options="{
...,
validator: {
type?: 'text' | 'number' | 'email' | 'tel' | 'date' | 'time',
min?: (number),
max?: (number),
step?: (number),
minlength?: (number, text),
maxlength?: (number, text),
custom?: (function),
pattern?: (RegExString),
errorText?: (string | Object)
errorHTML?: (string | Object)
}
}"
/>
validator​
validator: { min: 5, max: 10, step: 0.1 }
validator object