input: add maxLength property

This commit is contained in:
jean-emmanuel 2022-10-24 11:59:27 +02:00
parent 0bb3652898
commit 7b06f7e1a8
2 changed files with 18 additions and 0 deletions

View file

@ -28,6 +28,7 @@ class Input extends Canvas {
'- `^[0-9]*$` accepts digits only, any number of them',
'- `/^[a-z\s]{0,10}$/i` accept between 0 and 10 alphabetic characters and spaces (case insensitive)',
]},
maxLength: {type: 'number', value: '', help: ['Maximum number of characters allowed']}
},
})
@ -66,6 +67,13 @@ class Input extends Canvas {
this.input.inputMode = 'decimal'
}
if (this.getProp('maxLength') !== '') {
this.maxLength = parseInt(this.getProp('maxLength'))
this.input.maxLength = this.maxLength
} else {
this.maxLength = -1
}
var asYouType = this.getProp('asYouType')
if (this.getProp('validation') !== '') {
@ -156,6 +164,11 @@ class Input extends Canvas {
return
}
if (this.maxLength !== -1 && this.getStringValue(v).length > this.maxLength) {
v = this.getStringValue(v).substr(0, this.maxLength)
this.input.value = v
}
try {
this.value = JSON.parse(v)
} catch (err) {