diff --git a/components/DatePicker.qml b/components/DatePicker.qml index 9d0cbf20..ac67f8ed 100644 --- a/components/DatePicker.qml +++ b/components/DatePicker.qml @@ -35,6 +35,10 @@ Item { property bool expanded: false property date currentDate property bool showCurrentDate: true + property color backgroundColor : "#FFFFFF" + property color errorColor : "#FFDDDD" + property bool error: false + height: 37 width: 156 @@ -56,7 +60,6 @@ Item { Item { id: head anchors.fill: parent - Rectangle { anchors.left: parent.left anchors.right: parent.right @@ -64,6 +67,7 @@ Item { //radius: 4 y: 0 color: "#DBDBDB" + } Rectangle { @@ -74,7 +78,7 @@ Item { anchors.rightMargin: datePicker.expanded ? 1 : 0 //radius: 4 y: 1 - color: "#FFFFFF" + color: datePicker.error ? datePicker.errorColor : datePicker.backgroundColor } Item { diff --git a/pages/History.qml b/pages/History.qml index e31473ae..ab79084f 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -87,6 +87,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 @@ -162,6 +176,9 @@ Rectangle { anchors.rightMargin: 17 anchors.topMargin: 5 placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString + validator: RegExpValidator { + regExp: /[0-9a-fA-F]+/ + } } @@ -211,6 +228,10 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate > toDatePicker.currentDate + onFilterChanged() + } } // DateTo picker @@ -232,8 +253,14 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 z: 2 + onCurrentDateChanged: { + error = currentDate < fromDatePicker.currentDate + onFilterChanged() + } } + + StandardButton { id: filterButton anchors.bottom: toDatePicker.bottom @@ -247,15 +274,29 @@ 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) { model.amountFromFilter = parseFloat(amountFromLine.text) + } else { + // negative value disables filter here; + model.amountFromFilter = -1; } + if (amountToLine.text.length) { model.amountToFilter = parseFloat(amountToLine.text) + } else { + // negative value disables filter here; + model.amountToFilter = -1; } var directionFilter = transactionsModel.get(transactionTypeDropdown.currentIndex).value @@ -264,7 +305,6 @@ Rectangle { } selectedAmount.text = getSelectedAmount() - } } @@ -336,6 +376,17 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 width: 156 + 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 { @@ -357,6 +408,18 @@ Rectangle { anchors.leftMargin: 17 anchors.topMargin: 5 width: 156 + 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() + } + } Item {