Improve form validation
This commit is contained in:
parent
191859e18a
commit
fbc19db942
|
|
@ -117,7 +117,7 @@ class ClientEditDetailsState extends State<ClientEditDetails> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed() {
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
|
|
@ -191,7 +191,7 @@ class ClientEditDetailsState extends State<ClientEditDetails> {
|
|||
validator: (String val) => !viewModel.client.hasNameSet
|
||||
? AppLocalization.of(context).pleaseEnterAClientOrContactName
|
||||
: null,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
label: localization.name,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: !kIsWeb && (Platform.isIOS || Platform.isAndroid)
|
||||
|
|
@ -219,7 +219,7 @@ class ClientEditDetailsState extends State<ClientEditDetails> {
|
|||
DecoratedFormField(
|
||||
label: localization.number,
|
||||
controller: _numberController,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
if (memoizedGroupList(state.groupState.map).isNotEmpty)
|
||||
|
|
@ -238,50 +238,50 @@ class ClientEditDetailsState extends State<ClientEditDetails> {
|
|||
DecoratedFormField(
|
||||
label: localization.idNumber,
|
||||
controller: _idNumberController,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.vatNumber,
|
||||
controller: _vatNumberController,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.website,
|
||||
controller: _websiteController,
|
||||
keyboardType: TextInputType.url,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.phone,
|
||||
controller: _phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom1Controller,
|
||||
field: CustomFieldType.client1,
|
||||
value: client.customValue1,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.client2,
|
||||
value: client.customValue2,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.client3,
|
||||
value: client.customValue3,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.client4,
|
||||
value: client.customValue4,
|
||||
onSavePressed: (_) => _onSavePressed(),
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -132,6 +132,16 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = AppLocalization.of(context);
|
||||
|
|
@ -145,15 +155,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
? localization.newProduct
|
||||
: localization.editProduct,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: AppForm(
|
||||
formKey: _formKey,
|
||||
focusNode: _focusNode,
|
||||
|
|
@ -170,7 +172,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterAProductKey
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
|
|
@ -184,7 +186,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
controller: _priceController,
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
decimal: true, signed: true),
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
if (company.enableProductQuantity)
|
||||
DecoratedFormField(
|
||||
|
|
@ -192,7 +194,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
controller: _quantityController,
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
decimal: true, signed: true),
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
if (company.enableProductCost)
|
||||
DecoratedFormField(
|
||||
|
|
@ -200,7 +202,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
controller: _costController,
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
decimal: true, signed: true),
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
if (company.enableFirstItemTaxRate ||
|
||||
product.taxName1.isNotEmpty)
|
||||
|
|
@ -239,32 +241,32 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
controller: _custom1Controller,
|
||||
field: CustomFieldType.product1,
|
||||
value: product.customValue1,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.product2,
|
||||
value: product.customValue2,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.product3,
|
||||
value: product.customValue3,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.product4,
|
||||
value: product.customValue4,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
if (company.trackInventory) ...[
|
||||
DecoratedFormField(
|
||||
keyboardType: TextInputType.number,
|
||||
controller: _stockQuantityController,
|
||||
label: localization.stockQuantity,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
if (company.stockNotification) ...[
|
||||
SizedBox(height: 16),
|
||||
|
|
@ -284,7 +286,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
company.stockNotificationThreshold != 0)
|
||||
? ' • ${localization.defaultWord} ${company.stockNotificationThreshold}'
|
||||
: ''),
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -116,6 +116,16 @@ class _ProjectEditState extends State<ProjectEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -127,15 +137,7 @@ class _ProjectEditState extends State<ProjectEdit> {
|
|||
entity: project,
|
||||
title: project.isNew ? localization.newProject : localization.editProject,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
|
|
@ -153,7 +155,7 @@ class _ProjectEditState extends State<ProjectEdit> {
|
|||
keyboardType: TextInputType.text,
|
||||
autofocus: true,
|
||||
label: localization.projectName,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
project.isNew
|
||||
? EntityDropdown(
|
||||
|
|
@ -180,7 +182,7 @@ class _ProjectEditState extends State<ProjectEdit> {
|
|||
controller: _numberController,
|
||||
label: localization.projectNumber,
|
||||
keyboardType: TextInputType.text,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
UserPicker(
|
||||
userId: project.assignedUserId,
|
||||
|
|
@ -200,38 +202,38 @@ class _ProjectEditState extends State<ProjectEdit> {
|
|||
decimal: true, signed: true),
|
||||
controller: _hoursController,
|
||||
label: localization.budgetedHours,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
DecoratedFormField(
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
decimal: true, signed: true),
|
||||
controller: _taskRateController,
|
||||
label: localization.taskRate,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom1Controller,
|
||||
field: CustomFieldType.project1,
|
||||
value: project.customValue1,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.project2,
|
||||
value: project.customValue2,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.project3,
|
||||
value: project.customValue3,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.project4,
|
||||
value: project.customValue4,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
DecoratedFormField(
|
||||
maxLines: 4,
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ class _ClientPortalState extends State<ClientPortal>
|
|||
state.isHosted
|
||||
? localization.pleaseEnterAValue
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
if (state.isEnterprisePlan)
|
||||
|
|
|
|||
|
|
@ -268,9 +268,11 @@ class _CompanyDetailsState extends State<CompanyDetails>
|
|||
DecoratedFormField(
|
||||
label: localization.name,
|
||||
controller: _nameController,
|
||||
/*
|
||||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterAName
|
||||
: null,
|
||||
*/
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ class _EmailSettingsState extends State<EmailSettings> {
|
|||
GlobalKey<FormState>(debugLabel: '_emailSettings');
|
||||
|
||||
FocusScopeNode _focusNode;
|
||||
bool autoValidate = false;
|
||||
|
||||
final _fromNameController = TextEditingController();
|
||||
final _replyToEmailController = TextEditingController();
|
||||
|
|
|
|||
|
|
@ -138,6 +138,16 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -186,15 +196,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
? localization.newSubscription
|
||||
: localization.editSubscription,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
appBarBottom: TabBar(
|
||||
key: ValueKey(state.settingsUIState.updatedAt),
|
||||
controller: _controller,
|
||||
|
|
@ -223,7 +225,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
DecoratedFormField(
|
||||
controller: _nameController,
|
||||
label: localization.name,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DynamicSelector(
|
||||
|
|
@ -371,7 +373,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
DecoratedFormField(
|
||||
label: localization.promoCode,
|
||||
controller: _promoCodeController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DiscountField(
|
||||
|
|
@ -391,7 +393,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
label: localization.returnUrl,
|
||||
controller: _returnUrlController,
|
||||
keyboardType: TextInputType.url,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
BoolDropdownButton(
|
||||
label: localization.allowQueryOverrides,
|
||||
|
|
@ -447,7 +449,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
|
||||
],
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
@ -461,7 +463,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
label: localization.webhookUrl,
|
||||
controller: _postPurchaseUrlController,
|
||||
keyboardType: TextInputType.url,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
AppDropdownButton<String>(
|
||||
showBlank: true,
|
||||
|
|
@ -487,7 +489,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
child: DecoratedFormField(
|
||||
label: localization.headerKey,
|
||||
controller: _postPurchaseHeaderKeyController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
onChanged: (value) => setState(() {}),
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
|
|
@ -499,7 +501,7 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
|
|||
child: DecoratedFormField(
|
||||
label: localization.headerValue,
|
||||
controller: _postPurchaseHeaderValueController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
onChanged: (value) => setState(() {}),
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -68,6 +68,16 @@ class _TaskStatusEditState extends State<TaskStatusEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -80,15 +90,7 @@ class _TaskStatusEditState extends State<TaskStatusEdit> {
|
|||
? localization.newTaskStatus
|
||||
: localization.editTaskStatus,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
|
|
@ -104,7 +106,7 @@ class _TaskStatusEditState extends State<TaskStatusEdit> {
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterAName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
FormColorPicker(
|
||||
initialValue: taskStatus.color,
|
||||
|
|
|
|||
|
|
@ -75,6 +75,16 @@ class _TaxRateEditState extends State<TaxRateEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -85,7 +95,7 @@ class _TaxRateEditState extends State<TaxRateEdit> {
|
|||
title: viewModel.taxRate.isNew
|
||||
? localization.newTaxRate
|
||||
: localization.editTaxRate,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
onCancelPressed: viewModel.onCancelPressed,
|
||||
body: AppForm(
|
||||
focusNode: _focusNode,
|
||||
|
|
@ -100,14 +110,14 @@ class _TaxRateEditState extends State<TaxRateEdit> {
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterAName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.rate,
|
||||
controller: _rateController,
|
||||
isPercent: true,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -67,6 +67,16 @@ class _TokenEditState extends State<TokenEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -77,15 +87,7 @@ class _TokenEditState extends State<TokenEdit> {
|
|||
entity: token,
|
||||
title: token.isNew ? localization.newToken : localization.editToken,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
|
|
@ -101,7 +103,7 @@ class _TokenEditState extends State<TokenEdit> {
|
|||
value.isEmpty || value.trim().isEmpty
|
||||
? localization.pleaseEnterAName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -139,6 +139,16 @@ class _UserEditState extends State<UserEdit>
|
|||
user.rebuild((b) => b..userCompany.permissions = permissionsString));
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -167,15 +177,7 @@ class _UserEditState extends State<UserEdit>
|
|||
],
|
||||
),
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: AppTabForm(
|
||||
focusNode: _focusNode,
|
||||
formKey: _formKey,
|
||||
|
|
@ -192,7 +194,7 @@ class _UserEditState extends State<UserEdit>
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterAFirstName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.name,
|
||||
),
|
||||
DecoratedFormField(
|
||||
|
|
@ -201,7 +203,7 @@ class _UserEditState extends State<UserEdit>
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterALastName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.name,
|
||||
),
|
||||
DecoratedFormField(
|
||||
|
|
@ -210,45 +212,45 @@ class _UserEditState extends State<UserEdit>
|
|||
validator: (val) => val.isEmpty || val.trim().isEmpty
|
||||
? localization.pleaseEnterYourEmail
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
DecoratedFormField(
|
||||
label: localization.phone,
|
||||
controller: _phoneController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
/*
|
||||
PasswordFormField(
|
||||
controller: _passwordController,
|
||||
autoValidate: autoValidate,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
*/
|
||||
CustomField(
|
||||
controller: _custom1Controller,
|
||||
field: CustomFieldType.user1,
|
||||
value: user.customValue1,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.user2,
|
||||
value: user.customValue2,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.user3,
|
||||
value: user.customValue3,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.user4,
|
||||
value: user.customValue4,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ class VendorEditDetailsState extends State<VendorEditDetails> {
|
|||
final _custom3Controller = TextEditingController();
|
||||
final _custom4Controller = TextEditingController();
|
||||
|
||||
static final GlobalKey<FormState> _formKey =
|
||||
GlobalKey<FormState>(debugLabel: '_vendorEditDetails');
|
||||
final _debouncer = Debouncer();
|
||||
List<TextEditingController> _controllers;
|
||||
|
||||
|
|
@ -151,6 +153,16 @@ class VendorEditDetailsState extends State<VendorEditDetails> {
|
|||
..updatedAt = DateTime.now().millisecondsSinceEpoch));
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = AppLocalization.of(context);
|
||||
|
|
@ -159,107 +171,110 @@ class VendorEditDetailsState extends State<VendorEditDetails> {
|
|||
final state = viewModel.state;
|
||||
final isFullscreen = state.prefState.isEditorFullScreen(EntityType.vendor);
|
||||
|
||||
return FormCard(
|
||||
isLast: true,
|
||||
padding: isFullscreen
|
||||
? const EdgeInsets.only(
|
||||
left: kMobileDialogPadding,
|
||||
top: kMobileDialogPadding,
|
||||
right: kMobileDialogPadding / 2,
|
||||
)
|
||||
: null,
|
||||
children: <Widget>[
|
||||
DecoratedFormField(
|
||||
autofocus: true,
|
||||
controller: _nameController,
|
||||
validator: (String val) => val == null || val.isEmpty
|
||||
? AppLocalization.of(context).pleaseEnterAName
|
||||
: null,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
label: localization.name,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: !kIsWeb && (Platform.isIOS || Platform.isAndroid)
|
||||
? InputDecoration(
|
||||
labelText: localization.name,
|
||||
suffixIcon: IconButton(
|
||||
alignment: Alignment.bottomCenter,
|
||||
color: Theme.of(context).cardColor,
|
||||
icon: Icon(
|
||||
Icons.person,
|
||||
color: Colors.grey,
|
||||
),
|
||||
onPressed: () async {
|
||||
final contact = await getDeviceContact();
|
||||
if (contact != null) {
|
||||
setState(() {
|
||||
_setContactControllers(contact);
|
||||
});
|
||||
}
|
||||
}),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
if (vendor.isOld)
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: FormCard(
|
||||
isLast: true,
|
||||
padding: isFullscreen
|
||||
? const EdgeInsets.only(
|
||||
left: kMobileDialogPadding,
|
||||
top: kMobileDialogPadding,
|
||||
right: kMobileDialogPadding / 2,
|
||||
)
|
||||
: null,
|
||||
children: <Widget>[
|
||||
DecoratedFormField(
|
||||
label: localization.number,
|
||||
controller: _numberController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
autofocus: true,
|
||||
controller: _nameController,
|
||||
validator: (String val) => val == null || val.isEmpty
|
||||
? AppLocalization.of(context).pleaseEnterAName
|
||||
: null,
|
||||
onSavePressed: _onSavePressed,
|
||||
label: localization.name,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: !kIsWeb && (Platform.isIOS || Platform.isAndroid)
|
||||
? InputDecoration(
|
||||
labelText: localization.name,
|
||||
suffixIcon: IconButton(
|
||||
alignment: Alignment.bottomCenter,
|
||||
color: Theme.of(context).cardColor,
|
||||
icon: Icon(
|
||||
Icons.person,
|
||||
color: Colors.grey,
|
||||
),
|
||||
onPressed: () async {
|
||||
final contact = await getDeviceContact();
|
||||
if (contact != null) {
|
||||
setState(() {
|
||||
_setContactControllers(contact);
|
||||
});
|
||||
}
|
||||
}),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
if (vendor.isOld)
|
||||
DecoratedFormField(
|
||||
label: localization.number,
|
||||
controller: _numberController,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
UserPicker(
|
||||
userId: vendor.assignedUserId,
|
||||
onChanged: (userId) => viewModel
|
||||
.onChanged(vendor.rebuild((b) => b..assignedUserId = userId)),
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _idNumberController,
|
||||
label: localization.idNumber,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
UserPicker(
|
||||
userId: vendor.assignedUserId,
|
||||
onChanged: (userId) => viewModel
|
||||
.onChanged(vendor.rebuild((b) => b..assignedUserId = userId)),
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _idNumberController,
|
||||
label: localization.idNumber,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _vatNumberController,
|
||||
label: localization.vatNumber,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _websiteController,
|
||||
label: localization.website,
|
||||
keyboardType: TextInputType.url,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _phoneController,
|
||||
label: localization.phone,
|
||||
keyboardType: TextInputType.phone,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom1Controller,
|
||||
field: CustomFieldType.vendor1,
|
||||
value: vendor.customValue1,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.vendor2,
|
||||
value: vendor.customValue2,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.vendor3,
|
||||
value: vendor.customValue3,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.vendor4,
|
||||
value: vendor.customValue4,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
),
|
||||
],
|
||||
DecoratedFormField(
|
||||
controller: _vatNumberController,
|
||||
label: localization.vatNumber,
|
||||
onSavePressed: _onSavePressed,
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _websiteController,
|
||||
label: localization.website,
|
||||
keyboardType: TextInputType.url,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
DecoratedFormField(
|
||||
controller: _phoneController,
|
||||
label: localization.phone,
|
||||
keyboardType: TextInputType.phone,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom1Controller,
|
||||
field: CustomFieldType.vendor1,
|
||||
value: vendor.customValue1,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom2Controller,
|
||||
field: CustomFieldType.vendor2,
|
||||
value: vendor.customValue2,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom3Controller,
|
||||
field: CustomFieldType.vendor3,
|
||||
value: vendor.customValue3,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
CustomField(
|
||||
controller: _custom4Controller,
|
||||
field: CustomFieldType.vendor4,
|
||||
value: vendor.customValue4,
|
||||
onSavePressed: _onSavePressed,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,16 @@ class _WebhookEditState extends State<WebhookEdit> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onSavePressed(BuildContext context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.viewModel.onSavePressed(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = widget.viewModel;
|
||||
|
|
@ -88,15 +98,7 @@ class _WebhookEditState extends State<WebhookEdit> {
|
|||
entity: webhook,
|
||||
title: webhook.isNew ? localization.newWebhook : localization.editWebhook,
|
||||
onCancelPressed: (context) => viewModel.onCancelPressed(context),
|
||||
onSavePressed: (context) {
|
||||
final bool isValid = _formKey.currentState.validate();
|
||||
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.onSavePressed(context);
|
||||
},
|
||||
onSavePressed: _onSavePressed,
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Builder(builder: (BuildContext context) {
|
||||
|
|
@ -150,7 +152,7 @@ class _WebhookEditState extends State<WebhookEdit> {
|
|||
child: DecoratedFormField(
|
||||
label: localization.headerKey,
|
||||
controller: _headerKeyController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
onChanged: (value) => setState(() {}),
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
|
|
@ -162,7 +164,7 @@ class _WebhookEditState extends State<WebhookEdit> {
|
|||
child: DecoratedFormField(
|
||||
label: localization.headerValue,
|
||||
controller: _headerValueController,
|
||||
onSavePressed: viewModel.onSavePressed,
|
||||
onSavePressed: _onSavePressed,
|
||||
onChanged: (value) => setState(() {}),
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue