mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 13:25:40 +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:
		| @@ -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()); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user