Protect field/area text binding if no default text
This commit is contained in:
parent
4752abf6e5
commit
24e657d193
|
@ -17,8 +17,8 @@ TextArea {
|
||||||
|
|
||||||
property var focusItemOnTab: null
|
property var focusItemOnTab: null
|
||||||
property var disabledText: null
|
property var disabledText: null
|
||||||
property string defaultText: ""
|
property var defaultText: null // XXX test me
|
||||||
readonly property bool changed: text !== defaultText
|
readonly property bool changed: text !== (defaultText || "")
|
||||||
|
|
||||||
property alias backgroundColor: textAreaBackground.color
|
property alias backgroundColor: textAreaBackground.color
|
||||||
property color borderColor: theme.controls.textArea.border
|
property color borderColor: theme.controls.textArea.border
|
||||||
|
@ -28,11 +28,11 @@ TextArea {
|
||||||
property string previousDefaultText: "" // private
|
property string previousDefaultText: "" // private
|
||||||
|
|
||||||
|
|
||||||
function reset() { clear(); text = Qt.binding(() => defaultText) }
|
function reset() { clear(); text = Qt.binding(() => defaultText || "") }
|
||||||
function insertAtCursor(text) { insert(cursorPosition, text) }
|
function insertAtCursor(text) { insert(cursorPosition, text) }
|
||||||
|
|
||||||
|
|
||||||
text: defaultText
|
text: defaultText || ""
|
||||||
opacity: enabled ? 1 : theme.disabledElementsOpacity
|
opacity: enabled ? 1 : theme.disabledElementsOpacity
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
leftPadding: theme.spacing
|
leftPadding: theme.spacing
|
||||||
|
@ -77,9 +77,10 @@ TextArea {
|
||||||
|
|
||||||
onTextChanged: window.saveState(this)
|
onTextChanged: window.saveState(this)
|
||||||
|
|
||||||
onActiveFocusChanged: text = text // Break binding
|
onActiveFocusChanged:
|
||||||
|
if (defaultText !== null) text = text // Break binding
|
||||||
|
|
||||||
onDefaultTextChanged: {
|
onDefaultTextChanged: if (defaultText !== null) {
|
||||||
if (text === previousDefaultText)
|
if (text === previousDefaultText)
|
||||||
text = Qt.binding(() => defaultText)
|
text = Qt.binding(() => defaultText)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import QtQuick.Controls 2.12
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: field
|
id: field
|
||||||
text: defaultText
|
text: defaultText || ""
|
||||||
opacity: enabled ? 1 : theme.disabledElementsOpacity
|
opacity: enabled ? 1 : theme.disabledElementsOpacity
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
leftPadding: theme.spacing
|
leftPadding: theme.spacing
|
||||||
|
@ -50,9 +50,10 @@ TextField {
|
||||||
|
|
||||||
onTextChanged: window.saveState(this)
|
onTextChanged: window.saveState(this)
|
||||||
|
|
||||||
onActiveFocusChanged: text = text // Break binding
|
onActiveFocusChanged:
|
||||||
|
if (defaultText !== null) text = text // Break binding
|
||||||
|
|
||||||
onDefaultTextChanged: {
|
onDefaultTextChanged: if (defaultText !== null) {
|
||||||
if (text === previousDefaultText)
|
if (text === previousDefaultText)
|
||||||
text = Qt.binding(() => defaultText)
|
text = Qt.binding(() => defaultText)
|
||||||
|
|
||||||
|
@ -89,13 +90,13 @@ TextField {
|
||||||
property color focusedBorderColor: theme.controls.textField.focusedBorder
|
property color focusedBorderColor: theme.controls.textField.focusedBorder
|
||||||
|
|
||||||
property var disabledText: null
|
property var disabledText: null
|
||||||
property string defaultText: ""
|
property var defaultText: null
|
||||||
readonly property bool changed: text !== defaultText
|
readonly property bool changed: text !== (defaultText || "")
|
||||||
|
|
||||||
property string previousDefaultText: "" // private
|
property string previousDefaultText: "" // private
|
||||||
|
|
||||||
|
|
||||||
function reset() { clear(); text = Qt.binding(() => defaultText)}
|
function reset() { clear(); text = Qt.binding(() => defaultText || "")}
|
||||||
|
|
||||||
|
|
||||||
Binding on color {
|
Binding on color {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user