Adjust validation behavior

This commit is contained in:
Hillel Coren 2020-09-27 15:13:51 +03:00
parent 4934f6c8cd
commit 5901473a4f
10 changed files with 96 additions and 14 deletions

View File

@ -51,9 +51,18 @@ class _ClientEditState extends State<ClientEdit>
title: client.isNew ? localization.newClient : localization.editClient,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
appBarBottom: TabBar(

View File

@ -73,11 +73,19 @@ class _CreditEditState extends State<CreditEdit>
title: invoice.isNew ? localization.newCredit : localization.editCredit,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
widget.viewModel.onSavePressed(context);
viewModel.onSavePressed(context);
},
appBarBottom: state.prefState.isDesktop
? null

View File

@ -75,9 +75,18 @@ class _DocumentEditState extends State<DocumentEdit> {
title:
document.isNew ? localization.newDocument : localization.editDocument,
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
body: Form(

View File

@ -48,9 +48,18 @@ class _ExpenseEditState extends State<ExpenseEdit>
title: expense.isNew ? localization.newExpense : localization.editExpense,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
})
*/
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
appBarBottom: TabBar(

View File

@ -79,9 +79,16 @@ class _GroupEditState extends State<GroupEdit> {
onCancelPressed: (context) => viewModel.onCancelPressed(context),
title: group.isNew ? localization.newGroup : localization.editGroup,
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
setState(() {
autoValidate = !isValid ?? false;
});
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
body: Form(

View File

@ -78,11 +78,19 @@ class _InvoiceEditState extends State<InvoiceEdit>
title: invoice.isNew ? localization.newInvoice : localization.editInvoice,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
widget.viewModel.onSavePressed(context);
viewModel.onSavePressed(context);
},
appBarBottom: state.prefState.isDesktop
? null

View File

@ -73,11 +73,19 @@ class _QuoteEditState extends State<QuoteEdit>
title: invoice.isNew ? localization.newQuote : localization.editQuote,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
widget.viewModel.onSavePressed(context);
viewModel.onSavePressed(context);
},
appBarBottom: state.prefState.isDesktop
? null

View File

@ -74,11 +74,19 @@ class _TaskEditState extends State<TaskEdit>
title: task.isNew ? localization.newTask : localization.editTask,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
widget.viewModel.onSavePressed(context);
viewModel.onSavePressed(context);
},
appBarBottom: TabBar(
controller: _controller,

View File

@ -138,9 +138,16 @@ class _UserEditState extends State<UserEdit>
),
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
setState(() {
autoValidate = !isValid ?? false;
});
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
body: AppTabForm(

View File

@ -49,9 +49,18 @@ class _VendorEditState extends State<VendorEdit>
title: vendor.isNew ? localization.newVendor : localization.editVendor,
onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) {
if (!_formKey.currentState.validate()) {
final bool isValid = _formKey.currentState.validate();
/*
setState(() {
autoValidate = !isValid ?? false;
});
*/
if (!isValid) {
return;
}
viewModel.onSavePressed(context);
},
appBarBottom: TabBar(