From 466cae533323b041037f03b95cae3a34bd0328e4 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Wed, 10 Jun 2020 10:31:00 -0400 Subject: [PATCH] Check and display for some invalid inputs. --- src/contents/ui/main.qml | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 83d2d51..3e0718a 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -117,6 +117,15 @@ Kirigami.ApplicationWindow { title: qsTr("Add Vehicle") Layouts.ColumnLayout { anchors.fill: parent + Kirigami.InlineMessage { + Layouts.Layout.fillWidth: true + Layouts.Layout.leftMargin: 10 + Layouts.Layout.rightMargin: 10 + z: 9997 + type: Kirigami.MessageType.Error + showCloseButton: true + id: formError + } Kirigami.FormLayout { Layouts.Layout.alignment: Qt.AlignHCenter Layouts.Layout.fillWidth: true @@ -168,8 +177,13 @@ Kirigami.ApplicationWindow { text: qsTr("Add") highlighted: true onClicked: { - vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text); - router.popRoute(); + if(yearField.acceptableInput) { + vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text); + router.popRoute(); + } else { + formError.text = qsTr("Year is invalid!"); + formError.visible = true; + } } } @@ -247,6 +261,15 @@ Kirigami.ApplicationWindow { title: qsTr("Add Service Record") Layouts.ColumnLayout { anchors.fill: parent + Kirigami.InlineMessage { + Layouts.Layout.fillWidth: true + Layouts.Layout.leftMargin: 10 + Layouts.Layout.rightMargin: 10 + z: 9997 + type: Kirigami.MessageType.Error + showCloseButton: true + id: formError + } Kirigami.FormLayout { Layouts.Layout.alignment: Qt.AlignHCenter Layouts.Layout.fillWidth: true @@ -293,7 +316,7 @@ Kirigami.ApplicationWindow { inputMethodHints: Qt.ImhDigitsOnly validator: IntValidator { bottom: 0 - top: 400000 + top: 500000 } } @@ -309,8 +332,13 @@ Kirigami.ApplicationWindow { text: qsTr("Add") highlighted: true onClicked: { - recordModel.addNewRecord(providerField.text, typeField.text, -1, parseInt(milesField.text), notesField.text); //TODO: add proper date - router.popRoute(); + if(milesField.acceptableInput) { + recordModel.addNewRecord(providerField.text, typeField.text, -1, parseInt(milesField.text), notesField.text); //TODO: add proper date + router.popRoute(); + } else { + formError.text = qsTr("Invalid number of miles."); + formError.visible = true; + } } } Controls.Button { -- GitLab