2
0
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)
Some checks are pending
Android / build (push) Waiting to run
CI / test (push) Waiting to run
iOS / build (push) Waiting to run

* 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:
Oliver 2024-09-27 23:08:46 +10:00 committed by GitHub
parent ad48e5e172
commit 538a3d6ff6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,8 @@
### 0.16.5 - September 2024
---
- Allow blank values to be entered into numerical fields
### 0.16.4 - September 2024
---

View File

@ -471,7 +471,14 @@ class APIFormField {
// Construct a floating point numerical input field
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(
decoration: InputDecoration(
@ -481,9 +488,15 @@ class APIFormField {
helperStyle: _helperStyle(),
hintText: placeholderText,
),
initialValue: simpleNumberString(initial),
initialValue: initial,
keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true),
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());