diff --git a/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml b/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml index e35e7fe287..c53aff8167 100644 --- a/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml +++ b/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml @@ -39,6 +39,7 @@ Item { property real minimumHeight: 0 property real maximumHeight: 0 + property int maximumLength: 0 property bool valid: true @@ -128,17 +129,17 @@ Item { TextEdit { id: edit + property string previousText: text + width: flick.width selectByMouse: true selectionColor: Theme.palette.primaryColor2 selectedTextColor: color anchors.verticalCenter: parent.verticalCenter focus: true - font.pixelSize: 15 font.family: Theme.palette.baseFont.name color: Theme.palette.directColor1 - onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) wrapMode: TextEdit.NoWrap @@ -158,6 +159,21 @@ Item { } } + onTextChanged: { + if (statusBaseInput.maximumLength > 0) { + if (text.length > statusBaseInput.maximumLength) { + var cursor = cursorPosition; + text = previousText; + if (cursor > text.length) { + cursorPosition = text.length; + } else { + cursorPosition = cursor-1; + } + } + previousText = text + } + } + StatusBaseText { id: placeholder visible: edit.text.length === 0 diff --git a/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml b/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml index 0688ee66f3..0b06ed211f 100644 --- a/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml +++ b/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml @@ -66,6 +66,8 @@ Item { anchors.topMargin: charLimitLabel.visible ? 11 : 8 anchors.leftMargin: 16 anchors.rightMargin: 16 + + maximumLength: root.charLimit } StatusBaseText {