mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 21:46:46 +00:00
Improve formatting of error messages
Also run onSuccess function when form completes
This commit is contained in:
parent
64aed4b31a
commit
5c2f747b93
@ -60,6 +60,8 @@ class APIFormField {
|
|||||||
|
|
||||||
String get helpText => (data['help_text'] ?? '').toString();
|
String get helpText => (data['help_text'] ?? '').toString();
|
||||||
|
|
||||||
|
String get placeholderText => (data['placeholder'] ?? '').toString();
|
||||||
|
|
||||||
// Construct a widget for this input
|
// Construct a widget for this input
|
||||||
Widget constructField() {
|
Widget constructField() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -81,7 +83,17 @@ class APIFormField {
|
|||||||
return TextFormField(
|
return TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: required ? label + "*" : label,
|
labelText: required ? label + "*" : label,
|
||||||
hintText: helpText,
|
labelStyle: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 22,
|
||||||
|
color: hasErrors() ? Color.fromRGBO(250, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
|
||||||
|
),
|
||||||
|
helperText: helpText,
|
||||||
|
helperStyle: TextStyle(
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
color: hasErrors() ? Color.fromRGBO(205, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
|
||||||
|
),
|
||||||
|
hintText: placeholderText,
|
||||||
),
|
),
|
||||||
initialValue: value ?? '',
|
initialValue: value ?? '',
|
||||||
onSaved: (val) {
|
onSaved: (val) {
|
||||||
@ -89,7 +101,7 @@ class APIFormField {
|
|||||||
},
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (required && (value == null || value.isEmpty)) {
|
if (required && (value == null || value.isEmpty)) {
|
||||||
return L10().valueCannotBeEmpty;
|
// return L10().valueCannotBeEmpty;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -199,7 +211,12 @@ Future<void> launchApiForm(BuildContext context, String title, String url, Map<S
|
|||||||
// Now, launch a new widget!
|
// Now, launch a new widget!
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => APIFormWidget(title, url, formFields))
|
MaterialPageRoute(builder: (context) => APIFormWidget(
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
formFields,
|
||||||
|
onSuccess: onSuccess,
|
||||||
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,10 +231,20 @@ class APIFormWidget extends StatefulWidget {
|
|||||||
|
|
||||||
final List<APIFormField> fields;
|
final List<APIFormField> fields;
|
||||||
|
|
||||||
APIFormWidget(this.title, this.url, this.fields, {Key? key}) : super(key: key);
|
Function? onSuccess;
|
||||||
|
|
||||||
|
APIFormWidget(
|
||||||
|
this.title,
|
||||||
|
this.url,
|
||||||
|
this.fields,
|
||||||
|
{
|
||||||
|
Key? key,
|
||||||
|
this.onSuccess,
|
||||||
|
}
|
||||||
|
) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields);
|
_APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields, onSuccess);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +259,9 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
|
|
||||||
List<APIFormField> fields;
|
List<APIFormField> fields;
|
||||||
|
|
||||||
_APIFormWidgetState(this.title, this.url, this.fields) : super();
|
Function? onSuccess;
|
||||||
|
|
||||||
|
_APIFormWidgetState(this.title, this.url, this.fields, this.onSuccess) : super();
|
||||||
|
|
||||||
List<Widget> _buildForm() {
|
List<Widget> _buildForm() {
|
||||||
|
|
||||||
@ -252,7 +281,11 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
error,
|
error,
|
||||||
style: TextStyle(color: Color.fromRGBO(250, 50, 50, 1)),
|
style: TextStyle(
|
||||||
|
color: Color.fromRGBO(250, 50, 50, 1),
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -307,7 +340,12 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
|
|
||||||
// TODO: Display a snackBar
|
// TODO: Display a snackBar
|
||||||
|
|
||||||
// TODO: Run custom onSuccess function
|
// Run custom onSuccess function
|
||||||
|
var successFunc = onSuccess;
|
||||||
|
|
||||||
|
if (successFunc != null) {
|
||||||
|
successFunc();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
case 400:
|
case 400:
|
||||||
// Form submission / validation error
|
// Form submission / validation error
|
||||||
|
@ -174,13 +174,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
void _editPartDialog(BuildContext context) {
|
void _editPartDialog(BuildContext context) {
|
||||||
|
|
||||||
// Values which can be edited
|
|
||||||
var _name;
|
|
||||||
var _description;
|
|
||||||
var _ipn;
|
|
||||||
var _keywords;
|
|
||||||
var _link;
|
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
context,
|
context,
|
||||||
L10().editPart,
|
L10().editPart,
|
||||||
@ -196,52 +189,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
modelData: part.jsondata,
|
modelData: part.jsondata,
|
||||||
onSuccess: refresh,
|
onSuccess: refresh,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
showFormDialog(L10().editPart,
|
|
||||||
key: _editPartKey,
|
|
||||||
callback: () {
|
|
||||||
_savePart({
|
|
||||||
"name": _name,
|
|
||||||
"description": _description,
|
|
||||||
"IPN": _ipn,
|
|
||||||
"keywords": _keywords,
|
|
||||||
"link": _link
|
|
||||||
});
|
|
||||||
},
|
|
||||||
fields: <Widget>[
|
|
||||||
StringField(
|
|
||||||
label: L10().name,
|
|
||||||
initial: part.name,
|
|
||||||
onSaved: (value) => _name = value,
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().description,
|
|
||||||
initial: part.description,
|
|
||||||
onSaved: (value) => _description = value,
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().internalPartNumber,
|
|
||||||
initial: part.IPN,
|
|
||||||
allowEmpty: true,
|
|
||||||
onSaved: (value) => _ipn = value,
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().keywords,
|
|
||||||
initial: part.keywords,
|
|
||||||
allowEmpty: true,
|
|
||||||
onSaved: (value) => _keywords = value,
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().link,
|
|
||||||
initial: part.link,
|
|
||||||
allowEmpty: true,
|
|
||||||
onSaved: (value) => _link = value
|
|
||||||
)
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget headerTile() {
|
Widget headerTile() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user