add input type & max length

This commit is contained in:
王劲鹏 2021-05-31 11:30:51 +08:00 committed by osborn
parent af1ef2a103
commit 1291bb17b1
2 changed files with 30 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import QtQuick.Controls 2.5
import "util.mjs" as Util import "util.mjs" as Util
import "gravity.mjs" as Gravity import "gravity.mjs" as Gravity
TextArea { TextField {
property var wrapper property var wrapper
property var uuid: Util.uuidv4() property var uuid: Util.uuidv4()
@ -47,19 +47,11 @@ TextArea {
onWidthChanged: { onWidthChanged: {
bg.implicitWidth = width bg.implicitWidth = width
console.log(tag, uuid + " onWidthChanged: " + this.width) console.log(tag, uuid + " onWidthChanged: " + this.width)
let tempText = this.text
this.text = ""
this.text = tempText
} }
onHeightChanged: { onHeightChanged: {
bg.implicitHeight = height bg.implicitHeight = height
console.log(tag, uuid + " onHeightChanged: " + this.height) console.log(tag, uuid + " onHeightChanged: " + this.height)
let tempText = this.text
this.text = ""
this.text = tempText
} }
onTextChanged: { onTextChanged: {
@ -72,6 +64,31 @@ TextArea {
inputBridge.onFocusChange(wrapper, this.focus) inputBridge.onFocusChange(wrapper, this.focus)
} }
onMaximumLengthChanged: {
console.log(tag, uuid + " onMaximumLengthChanged: " + this.maximumLength)
}
property var inputType: 0
property var numberValidator: IntValidator {}
property var decimalValidator: DoubleValidator {}
property var alphabetValidator: RegExpValidator { regExp: /^[A-Z]+$/i}
onInputTypeChanged: {
console.log(tag, uuid + " onInputTypeChanged: " + this.inputType)
switch (inputType) {
case 1:
this.validator = numberValidator
break
case 2:
this.validator = decimalValidator
break
case 3:
this.validator = alphabetValidator
break
}
}
property var borderWidth: 0 property var borderWidth: 0
onBorderWidthChanged: { onBorderWidthChanged: {
bg.border.width = borderWidth bg.border.width = borderWidth

View File

@ -42,6 +42,10 @@ void DoricInputNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
view->setProperty("rightPadding", prop["right"].toDouble()); view->setProperty("rightPadding", prop["right"].toDouble());
view->setProperty("topPadding", prop["top"].toDouble()); view->setProperty("topPadding", prop["top"].toDouble());
view->setProperty("bottomPadding", prop["bottom"].toDouble()); view->setProperty("bottomPadding", prop["bottom"].toDouble());
} else if (name == "maxLength") {
view->setProperty("maximumLength", prop.toInt());
} else if (name == "inputType") {
view->setProperty("inputType", prop.toInt());
} else { } else {
DoricViewNode::blend(view, name, prop); DoricViewNode::blend(view, name, prop);
} }