From 02503e44ee1cdac01f48cbc180abb9b8cfcf0bcd Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 6 Nov 2016 19:11:19 +0300 Subject: [PATCH] History: amount and date filters validation --- pages/History.qml | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/pages/History.qml b/pages/History.qml index b4764e1c..f9fa9df7 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -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 { id: filterHeaderText @@ -141,6 +155,9 @@ Rectangle { anchors.rightMargin: 17 anchors.topMargin: 5 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.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate > toDatePicker.currentDate + onFilterChanged() + } } // DateTo picker @@ -211,8 +232,14 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate < fromDatePicker.currentDate + onFilterChanged() + } } + + StandardButton { id: filterButton anchors.bottom: toDatePicker.bottom @@ -226,9 +253,15 @@ Rectangle { pressedColor: "#4D0051" onClicked: { // Apply filter here; + 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 (amountFromLine.text.length) { @@ -325,7 +358,14 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation + bottom: 0 } + onTextChanged: { + // indicating error + amountFromLine.error = amountFromLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text) + onFilterChanged() + } + } Label { @@ -350,6 +390,13 @@ Rectangle { validator: DoubleValidator { locale: "C" notation: DoubleValidator.StandardNotation + bottom: 0.0 + } + + onTextChanged: { + // indicating error + amountToLine.error = amountToLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text) + onFilterChanged() } }