mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-19 16:39:10 +08:00
Add validator to material cost/weight spinboxes
This way only valid numbers can be entered CURA-8684
This commit is contained in:
parent
14767a92c6
commit
b2af6308e5
@ -271,13 +271,14 @@ OldControls.TabView
|
|||||||
text: spoolCostSpinBox.textFromValue(spoolCostSpinBox.value, spoolCostSpinBox.locale)
|
text: spoolCostSpinBox.textFromValue(spoolCostSpinBox.value, spoolCostSpinBox.locale)
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
background: Item {}
|
background: Item {}
|
||||||
|
validator: RegExpValidator { regExp: new RegExp("^" + base.currency + " ([0-9]+[.]?[0-9]*)?$") }
|
||||||
}
|
}
|
||||||
|
|
||||||
property int decimals: 2
|
property int decimals: 2
|
||||||
|
|
||||||
valueFromText: function(text) {
|
valueFromText: function(text) {
|
||||||
// remove all non-number tokens from input string so value can be parsed correctly
|
// remove all non-number tokens from input string so value can be parsed correctly
|
||||||
var value = Number(text.replace(",", ".").replace(/[^0-9.-]+/g, ""));
|
var value = Number(text.replace(",", ".").replace(/[^0-9.]+/g, ""));
|
||||||
var precision = Math.pow(10, spoolCostSpinBox.decimals);
|
var precision = Math.pow(10, spoolCostSpinBox.decimals);
|
||||||
return Math.round(value * precision) / precision;
|
return Math.round(value * precision) / precision;
|
||||||
}
|
}
|
||||||
@ -308,11 +309,12 @@ OldControls.TabView
|
|||||||
text: spoolWeightSpinBox.textFromValue(spoolWeightSpinBox.value, spoolWeightSpinBox.locale)
|
text: spoolWeightSpinBox.textFromValue(spoolWeightSpinBox.value, spoolWeightSpinBox.locale)
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
background: Item {}
|
background: Item {}
|
||||||
|
validator: RegExpValidator { regExp: new RegExp("^([0-9]+[.]?[0-9]*)? g$") }
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFromText: function(text, locale) {
|
valueFromText: function(text, locale) {
|
||||||
// remove all non-number tokens from input string so value can be parsed correctly
|
// remove all non-number tokens from input string so value can be parsed correctly
|
||||||
var value = Number(text.replace(",", ".").replace(/[^0-9.-]+/g, ""));
|
var value = Number(text.replace(",", ".").replace(/[^0-9.]+/g, ""));
|
||||||
return Math.round(value);
|
return Math.round(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user