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() {
|
Widget constructField() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "string":
|
case "string":
|
||||||
|
case "url":
|
||||||
return _constructString();
|
return _constructString();
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return _constructBoolean();
|
return _constructBoolean();
|
||||||
@ -86,8 +87,9 @@ class APIFormField {
|
|||||||
data["value"] = val;
|
data["value"] = val;
|
||||||
},
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
|
if (required && (value == null || value.isEmpty)) {
|
||||||
// TODO - Custom field validation
|
return L10().valueCannotBeEmpty;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -193,14 +195,39 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
|||||||
formFields.add(APIFormField(fieldName, remoteField));
|
formFields.add(APIFormField(fieldName, remoteField));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> widgets = [];
|
List<Widget> buildWidgets() {
|
||||||
|
List<Widget> widgets = [];
|
||||||
|
|
||||||
|
for (var ff in formFields) {
|
||||||
|
|
||||||
|
if (ff.hidden) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (var ff in formFields) {
|
|
||||||
if (!ff.hidden) {
|
|
||||||
widgets.add(ff.constructField());
|
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 {
|
void sendRequest(BuildContext context) async {
|
||||||
|
|
||||||
// Package up the form data
|
// Package up the form data
|
||||||
@ -252,44 +279,51 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
|
|||||||
|
|
||||||
OneContext().showDialog(
|
OneContext().showDialog(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return StatefulBuilder(
|
||||||
title: Text(title),
|
builder: (context, setState) {
|
||||||
actions: <Widget>[
|
return AlertDialog(
|
||||||
// Cancel button
|
title: Text(title),
|
||||||
TextButton(
|
actions: <Widget>[
|
||||||
child: Text(L10().cancel),
|
// Cancel button
|
||||||
onPressed: () {
|
TextButton(
|
||||||
Navigator.pop(context);
|
child: Text(L10().cancel),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
|
||||||
if (onCancel != null) {
|
if (onCancel != null) {
|
||||||
onCancel();
|
onCancel();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Save button
|
// Save button
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(L10().save),
|
child: Text(L10().save),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Validate the form
|
// Validate the form
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
sendRequest(context);
|
setState(() {
|
||||||
}
|
sendRequest(context);
|
||||||
},
|
_widgets = buildWidgets();
|
||||||
)
|
});
|
||||||
],
|
}
|
||||||
content: Form(
|
},
|
||||||
key: _formKey,
|
)
|
||||||
child: SingleChildScrollView(
|
],
|
||||||
child: Column(
|
content: Form(
|
||||||
mainAxisSize: MainAxisSize.min,
|
key: _formKey,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
child: SingleChildScrollView(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Column(
|
||||||
children: widgets
|
mainAxisSize: MainAxisSize.min,
|
||||||
)
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
)
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
)
|
children: _widgets,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
2
lib/l10n
2
lib/l10n
@ -1 +1 @@
|
|||||||
Subproject commit 84f6ed3faf63cbf371016e134196400e5f822759
|
Subproject commit 0870256fb97a27ccf0ab73b4665b886ca0abb4aa
|
@ -179,21 +179,19 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
var _keywords;
|
var _keywords;
|
||||||
var _link;
|
var _link;
|
||||||
|
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
"Edit Part",
|
L10().editPart,
|
||||||
part.url,
|
part.url,
|
||||||
{
|
{
|
||||||
"name": {},
|
"name": {},
|
||||||
"description": {},
|
"description": {},
|
||||||
"IPN": {
|
"IPN": {},
|
||||||
"hidden": true,
|
"keywords": {},
|
||||||
"label": "My custom label!",
|
|
||||||
},
|
|
||||||
"active": {},
|
"active": {},
|
||||||
|
"link": {},
|
||||||
},
|
},
|
||||||
modelData: part.jsondata,
|
modelData: part.jsondata,
|
||||||
onSuccess: refresh,
|
onSuccess: refresh,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user