InputValidator QML Type

Scriptable input control validation. More...

Import Statement: import ArcGIS.AppFramework 1.0


Detailed Description

The InputValidator component can be used to check the validation of a JavaScript function, useful for placing in a text field or another field that requires validation of its contents. This component is primarily used through providing the JavaScript function to the validate property.

This code sample demonstrates a potential usage of the InputValidator component. The text field provided specifically declares invalid any sentence that doesn't end in a full stop, or contains the word 'unicorn'. An additional function is also used to replace the word 'canine' with 'dog'.

TextField {
    validator: InputValidator {
        validate: function (input, position) {
            if (input.match(/unicorn/)) {
                return InputValidator.Invalid

            while (input.match(/canine/)) {
                input = input.replace(/canine/, 'dog')
                position -= 6
                position += 3

            let state = InputValidator.Intermediate
            if (input.endsWith('.')) {
                state = InputValidator.Acceptable

            return { input, position, state }
    placeholderText: qsTr("Type in a sentence ending with a fullstop. Avoid using 'unicorn' and 'canine'!")
    text: "A dog is man's best friend."
    selectByMouse: true


_State enumeration


Property Documentation

locale : string

The locale for the validator. This will normally be the same as the system default. This is typically used to parse localized data.

validate : var

This property accepts two arguments: an input (which is a string), and a position (which must be a number). The names of these arguments come from the JavaScript function being validated, and are not standard; if an argument isn't used in the JavaScript function, it can be omitted. It then produces one of a number of different types of values, depending on the result of the function's validation itself.

This can return three types of values:

If validate returns a boolean, true indicates that the function's validation is acceptable. If false, the validation is a plausible intermediate value.

If validate returns a number, 0 indicates that the function is clearly invalid, 1 indicates that the result is a clear intermediate value that could eventually become valid, and 2 indicates that the result is acceptable. This is also expressed in enum form, using InputValidator.Invalid, InputValidator.Intermediate, or InputValidator.Acceptable.

If validate returns an object, it will include a number describing the state (as above), as well as optionally the new input value and position; if the input or value hasn't changed, then that will be omitted.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.