mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Form updates
This commit is contained in:
parent
fd818740f7
commit
ca6226a596
@ -63,6 +63,7 @@ class APIFormField {
|
||||
Widget constructField() {
|
||||
switch (type) {
|
||||
case "string":
|
||||
case "url":
|
||||
return _constructString();
|
||||
case "boolean":
|
||||
return _constructBoolean();
|
||||
@ -86,8 +87,9 @@ class APIFormField {
|
||||
data["value"] = val;
|
||||
},
|
||||
validator: (value) {
|
||||
|
||||
// TODO - Custom field validation
|
||||
if (required && (value == null || value.isEmpty)) {
|
||||
return L10().valueCannotBeEmpty;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -193,14 +195,39 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
||||
formFields.add(APIFormField(fieldName, remoteField));
|
||||
}
|
||||
|
||||
List<Widget> buildWidgets() {
|
||||
List<Widget> widgets = [];
|
||||
|
||||
for (var ff in formFields) {
|
||||
if (!ff.hidden) {
|
||||
|
||||
if (ff.hidden) {
|
||||
continue;
|
||||
}
|
||||
|
||||
widgets.add(ff.constructField());
|
||||
|
||||
if (ff.hasErrors()) {
|
||||
for (String error in ff.errorMessages()) {
|
||||
widgets.add(
|
||||
ListTile(
|
||||
title: Text(
|
||||
error,
|
||||
style: TextStyle(color: Color.fromRGBO(250, 50, 50, 1))
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return widgets;
|
||||
}
|
||||
|
||||
|
||||
List<Widget> _widgets = buildWidgets();
|
||||
|
||||
|
||||
void sendRequest(BuildContext context) async {
|
||||
|
||||
// Package up the form data
|
||||
@ -252,6 +279,8 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
||||
|
||||
OneContext().showDialog(
|
||||
builder: (BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
actions: <Widget>[
|
||||
@ -274,7 +303,10 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
|
||||
setState(() {
|
||||
sendRequest(context);
|
||||
_widgets = buildWidgets();
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
@ -286,11 +318,13 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: widgets
|
||||
children: _widgets,
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
2
lib/l10n
2
lib/l10n
@ -1 +1 @@
|
||||
Subproject commit 84f6ed3faf63cbf371016e134196400e5f822759
|
||||
Subproject commit 0870256fb97a27ccf0ab73b4665b886ca0abb4aa
|
@ -179,18 +179,16 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
var _keywords;
|
||||
var _link;
|
||||
|
||||
|
||||
launchApiForm(
|
||||
"Edit Part",
|
||||
L10().editPart,
|
||||
part.url,
|
||||
{
|
||||
"name": {},
|
||||
"description": {},
|
||||
"IPN": {
|
||||
"hidden": true,
|
||||
"label": "My custom label!",
|
||||
},
|
||||
"IPN": {},
|
||||
"keywords": {},
|
||||
"active": {},
|
||||
"link": {},
|
||||
},
|
||||
modelData: part.jsondata,
|
||||
onSuccess: refresh,
|
||||
|
Loading…
x
Reference in New Issue
Block a user