History: amount and date filters validation

This commit is contained in:
Ilya Kitaev 2016-11-06 19:11:19 +03:00
parent 328b7b05d8
commit 02503e44ee

View file

@ -66,6 +66,20 @@ Rectangle {
} }
} }
function onFilterChanged() {
var datesValid = fromDatePicker.currentDate <= toDatePicker.currentDate
var amountsValid = amountFromLine.text === "" ? true :
amountToLine.text === "" ? true:
parseFloat(amountFromLine.text) <= parseFloat(amountToLine.text)
// reset error state if amount filter valid
if (amountsValid) {
amountFromLine.error = amountToLine.error = false
}
filterButton.enabled = datesValid && amountsValid
}
Text { Text {
id: filterHeaderText id: filterHeaderText
@ -141,6 +155,9 @@ Rectangle {
anchors.rightMargin: 17 anchors.rightMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString
validator: RegExpValidator {
regExp: /[0-9a-fA-F]+/
}
} }
@ -190,6 +207,10 @@ Rectangle {
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
z: 2 z: 2
onCurrentDateChanged: {
error = currentDate > toDatePicker.currentDate
onFilterChanged()
}
} }
// DateTo picker // DateTo picker
@ -211,8 +232,14 @@ Rectangle {
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
z: 2 z: 2
onCurrentDateChanged: {
error = currentDate < fromDatePicker.currentDate
onFilterChanged()
}
} }
StandardButton { StandardButton {
id: filterButton id: filterButton
anchors.bottom: toDatePicker.bottom anchors.bottom: toDatePicker.bottom
@ -226,9 +253,15 @@ Rectangle {
pressedColor: "#4D0051" pressedColor: "#4D0051"
onClicked: { onClicked: {
// Apply filter here; // Apply filter here;
model.paymentIdFilter = paymentIdLine.text model.paymentIdFilter = paymentIdLine.text
model.dateFromFilter = fromDatePicker.currentDate
model.dateToFilter = toDatePicker.currentDate if (fromDatePicker.currentDate > toDatePicker.currentDate) {
console.error("Invalid date filter set: ", fromDatePicker.currentDate, toDatePicker.currentDate)
} else {
model.dateFromFilter = fromDatePicker.currentDate
model.dateToFilter = toDatePicker.currentDate
}
if (advancedFilteringCheckBox.checked) { if (advancedFilteringCheckBox.checked) {
if (amountFromLine.text.length) { if (amountFromLine.text.length) {
@ -325,7 +358,14 @@ Rectangle {
validator: DoubleValidator { validator: DoubleValidator {
locale: "C" locale: "C"
notation: DoubleValidator.StandardNotation notation: DoubleValidator.StandardNotation
bottom: 0
} }
onTextChanged: {
// indicating error
amountFromLine.error = amountFromLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text)
onFilterChanged()
}
} }
Label { Label {
@ -350,6 +390,13 @@ Rectangle {
validator: DoubleValidator { validator: DoubleValidator {
locale: "C" locale: "C"
notation: DoubleValidator.StandardNotation notation: DoubleValidator.StandardNotation
bottom: 0.0
}
onTextChanged: {
// indicating error
amountToLine.error = amountToLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text)
onFilterChanged()
} }
} }