fix(AmountInput): Skip non-digits for max input length limit validation
Closes: #9718
This commit is contained in:
parent
405a8ee3ed
commit
0e60ac4933
|
@ -57,6 +57,18 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLocalizedDigitsCount(str, locale = null) {
|
||||||
|
if (!str)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
locale = locale || Qt.locale()
|
||||||
|
|
||||||
|
if (d.nonDigitCharacterRegExpLocale !== locale)
|
||||||
|
d.nonDigitCharacterRegExpLocale = locale
|
||||||
|
|
||||||
|
return str.replace(d.nonDigitCharacterRegExp, "").length
|
||||||
|
}
|
||||||
|
|
||||||
function currencyAmountToLocaleString(currencyAmount, options = null, locale = null) {
|
function currencyAmountToLocaleString(currencyAmount, options = null, locale = null) {
|
||||||
locale = locale || Qt.locale()
|
locale = locale || Qt.locale()
|
||||||
|
|
||||||
|
@ -146,6 +158,15 @@ QtObject {
|
||||||
secondDate.setHours(0, 0, 0)
|
secondDate.setHours(0, 0, 0)
|
||||||
return Math.round(Math.abs((firstDate - secondDate) / d.msInADay)) // Math.round: not all days are 24 hours long!
|
return Math.round(Math.abs((firstDate - secondDate) / d.msInADay)) // Math.round: not all days are 24 hours long!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property var nonDigitCharacterRegExpLocale
|
||||||
|
|
||||||
|
readonly property var nonDigitCharacterRegExp: {
|
||||||
|
const localizedNumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(
|
||||||
|
n => LocaleUtils.numberToLocaleString(n, 0, nonDigitCharacterRegExpLocale))
|
||||||
|
|
||||||
|
return new RegExp(`[^${localizedNumbers.join("")}]`, "g")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property Settings settings: Settings {
|
readonly property Settings settings: Settings {
|
||||||
|
|
|
@ -32,6 +32,11 @@ Input {
|
||||||
id: d
|
id: d
|
||||||
|
|
||||||
property real amount: 0
|
property real amount: 0
|
||||||
|
|
||||||
|
function getEffectiveDigitsCount(str) {
|
||||||
|
const digits = LocaleUtils.getLocalizedDigitsCount(text, root.locale)
|
||||||
|
return str.startsWith(locale.decimalPoint) ? digits + 1 : digits
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validator: DoubleValidator {
|
validator: DoubleValidator {
|
||||||
|
@ -53,7 +58,7 @@ Input {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text.length > root.maximumLength) {
|
if (d.getEffectiveDigitsCount(text) > root.maximumLength) {
|
||||||
root.validationError = qsTr("The maximum number of characters is %1").arg(root.maximumLength)
|
root.validationError = qsTr("The maximum number of characters is %1").arg(root.maximumLength)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue