input: add maxLength property
This commit is contained in:
parent
0bb3652898
commit
7b06f7e1a8
2 changed files with 18 additions and 0 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## 1.18.4
|
||||
|
||||
- widgets
|
||||
- input: add `maxLength` property
|
||||
|
||||
## 1.18.3
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue