Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenquan/fde0cd1582e8a7488226c8ce8f717621 to your computer and use it in GitHub Desktop.
Save stephenquan/fde0cd1582e8a7488226c8ce8f717621 to your computer and use it in GitHub Desktop.
AppStudio_20190703_InputValidatorTest.qml
import QtQuick 2.12
import QtQuick.Controls 2.5
import ArcGIS.AppFramework 1.0
Item {
TextField {
width: parent.width
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."
color: acceptableInput ? "green" : "red"
selectByMouse: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment