Check and display for some invalid inputs.

This commit is contained in:
2020-06-10 10:31:00 -04:00
parent 1852fbc6d2
commit 466cae5333

View File

@@ -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 {