Merge pull request #120

02503e4 History: amount and date filters validation (Ilya Kitaev)
328b7b0 History: amount filter: empty line disables filter (Ilya Kitaev)
69b4d46 DatePicker: 'error' property for indicating invalid input (Ilya Kitaev)
ead7ac8 Historty: DoubleValidator applied to "amount filter" fields (Ilya Kitaev)
This commit is contained in:
Riccardo Spagni 2016-11-11 12:41:57 +02:00
commit fc5fba23d6
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
2 changed files with 72 additions and 5 deletions

View file

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

View file

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