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