mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Allow null values for decimal fields (#539)
* Allow null values for decimal fields - fixes https://github.com/inventree/inventree-app/issues/538 * Update release notes * Fix initial value
This commit is contained in:
parent
ad48e5e172
commit
538a3d6ff6
@ -1,3 +1,8 @@
|
|||||||
|
### 0.16.5 - September 2024
|
||||||
|
---
|
||||||
|
|
||||||
|
- Allow blank values to be entered into numerical fields
|
||||||
|
|
||||||
### 0.16.4 - September 2024
|
### 0.16.4 - September 2024
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -471,7 +471,14 @@ class APIFormField {
|
|||||||
// Construct a floating point numerical input field
|
// Construct a floating point numerical input field
|
||||||
Widget _constructFloatField() {
|
Widget _constructFloatField() {
|
||||||
|
|
||||||
double initial = double.tryParse(value.toString()) ?? 0;
|
// Initial value: try to cast to a valid number
|
||||||
|
String initial = "";
|
||||||
|
|
||||||
|
double? initialNumber = double.tryParse(value.toString());
|
||||||
|
|
||||||
|
if (initialNumber != null) {
|
||||||
|
initial = simpleNumberString(initialNumber);
|
||||||
|
}
|
||||||
|
|
||||||
return TextFormField(
|
return TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -481,9 +488,15 @@ class APIFormField {
|
|||||||
helperStyle: _helperStyle(),
|
helperStyle: _helperStyle(),
|
||||||
hintText: placeholderText,
|
hintText: placeholderText,
|
||||||
),
|
),
|
||||||
initialValue: simpleNumberString(initial),
|
initialValue: initial,
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true),
|
keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
|
value = value?.trim() ?? "";
|
||||||
|
|
||||||
|
// Allow empty numbers, *if* this field is not required
|
||||||
|
if (value.isEmpty && !required) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
double? quantity = double.tryParse(value.toString());
|
double? quantity = double.tryParse(value.toString());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user