[do not squash] validation checking in textfield
rename
This commit is contained in:
parent
4170e1d5af
commit
1f764df150
5 changed files with 66 additions and 36 deletions
|
|
@ -52,6 +52,7 @@ list(APPEND _LINPHONEAPP_QML_FILES
|
||||||
view/Control/Form/Settings/ScreencastSettings.qml
|
view/Control/Form/Settings/ScreencastSettings.qml
|
||||||
|
|
||||||
view/Control/Input/Calendar.qml
|
view/Control/Input/Calendar.qml
|
||||||
|
view/Control/Input/DecoratedTextField.qml
|
||||||
view/Control/Input/DigitInput.qml
|
view/Control/Input/DigitInput.qml
|
||||||
view/Control/Input/NumericPad.qml
|
view/Control/Input/NumericPad.qml
|
||||||
view/Control/Input/PhoneNumberInput.qml
|
view/Control/Input/PhoneNumberInput.qml
|
||||||
|
|
@ -59,7 +60,6 @@ list(APPEND _LINPHONEAPP_QML_FILES
|
||||||
view/Control/Input/TextArea.qml
|
view/Control/Input/TextArea.qml
|
||||||
view/Control/Input/TextField.qml
|
view/Control/Input/TextField.qml
|
||||||
view/Control/Input/TimeComboBox.qml
|
view/Control/Input/TimeComboBox.qml
|
||||||
view/Control/Input/ValidatedTextField.qml
|
|
||||||
|
|
||||||
view/Control/Popup/DesktopPopup.qml
|
view/Control/Popup/DesktopPopup.qml
|
||||||
view/Control/Popup/InformationPopup.qml
|
view/Control/Popup/InformationPopup.qml
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ FocusScope{
|
||||||
property bool errorTextVisible: errorText.text.length > 0
|
property bool errorTextVisible: errorText.text.length > 0
|
||||||
implicitHeight: layout.implicitHeight
|
implicitHeight: layout.implicitHeight
|
||||||
implicitWidth: layout.implicitWidth
|
implicitWidth: layout.implicitWidth
|
||||||
|
|
||||||
|
function clearErrorText() {
|
||||||
|
errorText.clear()
|
||||||
|
}
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: layout
|
id: layout
|
||||||
spacing: 5 * DefaultStyle.dp
|
spacing: 5 * DefaultStyle.dp
|
||||||
|
|
|
||||||
|
|
@ -15,52 +15,33 @@ FormItemLayout {
|
||||||
property var title
|
property var title
|
||||||
property var placeHolder
|
property var placeHolder
|
||||||
property bool useTitleAsPlaceHolder: true
|
property bool useTitleAsPlaceHolder: true
|
||||||
property int idleTimeOut: 200
|
property bool canBeEmpty: true
|
||||||
property var isValid: function(text) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
property alias hidden: textField.hidden
|
property alias hidden: textField.hidden
|
||||||
property alias validator: textField.validator
|
property alias validator: textField.validator
|
||||||
property bool empty: mainItem.propertyOwner[mainItem.propertyName]?.length == 0
|
|
||||||
property bool canBeEmpty: true
|
property var isValid: function(text) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
contentItem: TextField {
|
contentItem: TextField {
|
||||||
id: textField
|
id: textField
|
||||||
property var initialReading: true
|
|
||||||
placeholderText: useTitleAsPlaceHolder ? mainItem.title : mainItem.placeHolder
|
placeholderText: useTitleAsPlaceHolder ? mainItem.title : mainItem.placeHolder
|
||||||
initialText: mainItem.propertyOwner[mainItem.propertyName]
|
initialText: mainItem.propertyOwner[mainItem.propertyName]
|
||||||
customWidth: mainItem.parent.width
|
customWidth: mainItem.parent.width
|
||||||
Timer {
|
propertyName: mainItem.propertyName
|
||||||
id: idleTimer
|
propertyOwner: mainItem.propertyOwner
|
||||||
running: false
|
canBeEmpty: mainItem.canBeEmpty
|
||||||
interval: mainItem.idleTimeOut
|
isValid: mainItem.isValid
|
||||||
repeat: false
|
onValidationChecked: (isValid) => {
|
||||||
onTriggered: textField.editingFinished()
|
if (isValid) return
|
||||||
}
|
if (!canBeEmpty && empty) {
|
||||||
onEditingFinished: {
|
|
||||||
updateText()
|
|
||||||
}
|
|
||||||
onTextChanged: {
|
|
||||||
idleTimer.restart()
|
|
||||||
updateText()
|
|
||||||
}
|
|
||||||
function updateText() {
|
|
||||||
mainItem.empty = text.length == 0
|
|
||||||
if (initialReading) {
|
|
||||||
initialReading = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!canBeEmpty && mainItem.empty) {
|
|
||||||
mainItem.errorMessage = qsTr("ne peut être vide")
|
mainItem.errorMessage = qsTr("ne peut être vide")
|
||||||
return
|
|
||||||
}
|
|
||||||
if (isValid(text)) {
|
|
||||||
mainItem.errorMessage = ""
|
|
||||||
if (mainItem.propertyOwner[mainItem.propertyName] != text)
|
|
||||||
mainItem.propertyOwner[mainItem.propertyName] = text
|
|
||||||
} else {
|
} else {
|
||||||
mainItem.errorMessage = qsTr("Format non reconnu")
|
mainItem.errorMessage = qsTr("Format non reconnu")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onTextChanged: mainItem.clearErrorText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +34,19 @@ Control.TextField {
|
||||||
property int pixelSize: 14 * DefaultStyle.dp
|
property int pixelSize: 14 * DefaultStyle.dp
|
||||||
property int weight: 400 * DefaultStyle.dp
|
property int weight: 400 * DefaultStyle.dp
|
||||||
|
|
||||||
|
// fill propertyName and propertyOwner to check text validity
|
||||||
|
property string propertyName
|
||||||
|
property var propertyOwner
|
||||||
|
property var initialReading: true
|
||||||
|
property var isValid: function(text) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
property int idleTimeOut: 200
|
||||||
|
property bool empty: mainItem.propertyOwner[mainItem.propertyName]?.length == 0
|
||||||
|
property bool canBeEmpty: true
|
||||||
|
|
||||||
|
signal validationChecked(bool valid)
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
text = initialText
|
text = initialText
|
||||||
}
|
}
|
||||||
|
|
@ -124,5 +137,36 @@ Control.TextField {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: rightMargin
|
anchors.rightMargin: rightMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validation textfield functions
|
||||||
|
Timer {
|
||||||
|
id: idleTimer
|
||||||
|
running: false
|
||||||
|
interval: mainItem.idleTimeOut
|
||||||
|
repeat: false
|
||||||
|
onTriggered: textField.editingFinished()
|
||||||
|
}
|
||||||
|
onEditingFinished: {
|
||||||
|
updateText()
|
||||||
|
}
|
||||||
|
onTextChanged: {
|
||||||
|
idleTimer.restart()
|
||||||
|
// updateText()
|
||||||
|
}
|
||||||
|
function updateText() {
|
||||||
|
mainItem.empty = text.length == 0
|
||||||
|
if (initialReading) {
|
||||||
|
initialReading = false
|
||||||
|
}
|
||||||
|
if (mainItem.empty && !mainItem.canBeEmpty) {
|
||||||
|
mainItem.validationChecked(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (isValid(text)) {
|
||||||
|
if (mainItem.propertyOwner[mainItem.propertyName] != text)
|
||||||
|
mainItem.propertyOwner[mainItem.propertyName] = text
|
||||||
|
mainItem.validationChecked(true)
|
||||||
|
} else mainItem.validationChecked(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ AbstractSettingsLayout {
|
||||||
propertyName: "expire"
|
propertyName: "expire"
|
||||||
propertyOwner: account.core
|
propertyOwner: account.core
|
||||||
title: qsTr("Expiration (en seconde)")
|
title: qsTr("Expiration (en seconde)")
|
||||||
|
canBeEmpty: false
|
||||||
isValid: function(text) { return !isNaN(Number(text)); }
|
isValid: function(text) { return !isNaN(Number(text)); }
|
||||||
}
|
}
|
||||||
ValidatedTextField {
|
ValidatedTextField {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue