2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

edit stock item

- Render choice fields
This commit is contained in:
Oliver
2021-07-26 22:26:56 +10:00
parent e8cb002e3c
commit 978cefd6bf
6 changed files with 86 additions and 20 deletions

View File

@ -111,6 +111,8 @@ class APIFormField {
String get placeholderText => (data['placeholder'] ?? '').toString();
List<dynamic> get choices => data["choices"] ?? [];
Future<void> loadInitialData() async {
// Only for "related fields"
@ -151,6 +153,8 @@ class APIFormField {
return _constructBoolean();
case "related field":
return _constructRelatedField();
case "choice":
return _constructChoiceField();
default:
return ListTile(
title: Text(
@ -163,6 +167,40 @@ class APIFormField {
}
}
Widget _constructChoiceField() {
dynamic _initial;
// Check if the current value is within the allowed values
for (var opt in choices) {
if (opt['value'] == value) {
_initial = opt;
break;
}
}
return DropdownSearch<dynamic>(
mode: Mode.BOTTOM_SHEET,
showSelectedItem: false,
selectedItem: _initial,
items: choices,
label: label,
hint: helpText,
onChanged: null,
showClearButton: !required,
itemAsString: (dynamic item) {
return item['display_name'];
},
onSaved: (item) {
if (item == null) {
data['value'] = null;
} else {
data['value'] = item['value'];
}
}
);
}
// Construct an input for a related field
Widget _constructRelatedField() {