[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/Input/Calendar.qml
|
||||
view/Control/Input/DecoratedTextField.qml
|
||||
view/Control/Input/DigitInput.qml
|
||||
view/Control/Input/NumericPad.qml
|
||||
view/Control/Input/PhoneNumberInput.qml
|
||||
|
|
@ -59,7 +60,6 @@ list(APPEND _LINPHONEAPP_QML_FILES
|
|||
view/Control/Input/TextArea.qml
|
||||
view/Control/Input/TextField.qml
|
||||
view/Control/Input/TimeComboBox.qml
|
||||
view/Control/Input/ValidatedTextField.qml
|
||||
|
||||
view/Control/Popup/DesktopPopup.qml
|
||||
view/Control/Popup/InformationPopup.qml
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ FocusScope{
|
|||
property bool errorTextVisible: errorText.text.length > 0
|
||||
implicitHeight: layout.implicitHeight
|
||||
implicitWidth: layout.implicitWidth
|
||||
|
||||
function clearErrorText() {
|
||||
errorText.clear()
|
||||
}
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
spacing: 5 * DefaultStyle.dp
|
||||
|
|
|
|||
|
|
@ -15,52 +15,33 @@ FormItemLayout {
|
|||
property var title
|
||||
property var placeHolder
|
||||
property bool useTitleAsPlaceHolder: true
|
||||
property int idleTimeOut: 200
|
||||
property var isValid: function(text) {
|
||||
return true;
|
||||
}
|
||||
property bool canBeEmpty: true
|
||||
|
||||
property alias hidden: textField.hidden
|
||||
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 {
|
||||
id: textField
|
||||
property var initialReading: true
|
||||
placeholderText: useTitleAsPlaceHolder ? mainItem.title : mainItem.placeHolder
|
||||
initialText: mainItem.propertyOwner[mainItem.propertyName]
|
||||
customWidth: mainItem.parent.width
|
||||
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
|
||||
return
|
||||
}
|
||||
if (!canBeEmpty && mainItem.empty) {
|
||||
propertyName: mainItem.propertyName
|
||||
propertyOwner: mainItem.propertyOwner
|
||||
canBeEmpty: mainItem.canBeEmpty
|
||||
isValid: mainItem.isValid
|
||||
onValidationChecked: (isValid) => {
|
||||
if (isValid) return
|
||||
if (!canBeEmpty && empty) {
|
||||
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 {
|
||||
mainItem.errorMessage = qsTr("Format non reconnu")
|
||||
}
|
||||
}
|
||||
onTextChanged: mainItem.clearErrorText()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,20 @@ Control.TextField {
|
|||
property string initialText
|
||||
property int pixelSize: 14 * 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: {
|
||||
text = initialText
|
||||
}
|
||||
|
|
@ -124,5 +137,36 @@ Control.TextField {
|
|||
anchors.right: parent.right
|
||||
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"
|
||||
propertyOwner: account.core
|
||||
title: qsTr("Expiration (en seconde)")
|
||||
canBeEmpty: false
|
||||
isValid: function(text) { return !isNaN(Number(text)); }
|
||||
}
|
||||
ValidatedTextField {
|
||||
|
|
|
|||
Loading…
Reference in a new issue