I have the following TextInput element:
TextInput {
id: textInput
text: m_init
anchors.centerIn: parent
font.family : "Helvetica"
font.pixelSize: 14
color: "black"
maximumLength: 2
smooth: true
inputMask: "HH"
states : [
State {
name: "EmptyInputLeft"
when: !text.length
PropertyChanges {
target: textInput
text : "00"
}
}
]
}
I would like to display 00 when everything has been removed from it by backspace. I've coded a State for this purpose but it does not work as expected. What am I doing wrong?
You have a: "QML TextInput: Binding loop detected for property "text"" error on your code above. The reason is that when you are setting the text to "00", the length changes, which fires the "when" clause again (and setting again), and causes the loop error.
Here is a work-around using a validator:
Or perhaps binding the text to a function:
in conjunction with the onTextChanged event, could yield better results: