Correct validation in email settings

This commit is contained in:
Hillel Coren 2023-03-03 13:30:21 +02:00
parent ee3d7c1b63
commit c99214301b
1 changed files with 28 additions and 5 deletions

View File

@ -124,6 +124,16 @@ class _EmailSettingsState extends State<EmailSettings> {
} }
} }
void _onSavePressed(BuildContext context) {
final bool isValid = _formKey.currentState.validate();
if (!isValid) {
return;
}
widget.viewModel.onSavePressed(context);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
@ -143,7 +153,7 @@ class _EmailSettingsState extends State<EmailSettings> {
return EditScaffold( return EditScaffold(
title: localization.emailSettings, title: localization.emailSettings,
onSavePressed: disableSave ? null : viewModel.onSavePressed, onSavePressed: disableSave ? null : _onSavePressed,
body: AppForm( body: AppForm(
formKey: _formKey, formKey: _formKey,
focusNode: _focusNode, focusNode: _focusNode,
@ -257,6 +267,10 @@ class _EmailSettingsState extends State<EmailSettings> {
label: localization.secret, label: localization.secret,
controller: _postmarkSecretController, controller: _postmarkSecretController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
onSavePressed: _onSavePressed,
validator: (value) => value.trim().isEmpty
? localization.pleaseEnterAValue
: null,
), ),
] else if (settings.emailSendingMethod == ] else if (settings.emailSendingMethod ==
SettingsEntity.EMAIL_SENDING_METHOD_MAILGUN) ...[ SettingsEntity.EMAIL_SENDING_METHOD_MAILGUN) ...[
@ -264,11 +278,19 @@ class _EmailSettingsState extends State<EmailSettings> {
label: localization.secret, label: localization.secret,
controller: _mailgunSecretController, controller: _mailgunSecretController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
onSavePressed: _onSavePressed,
validator: (value) => value.trim().isEmpty
? localization.pleaseEnterAValue
: null,
), ),
DecoratedFormField( DecoratedFormField(
label: localization.domain, label: localization.domain,
controller: _mailgunDomainController, controller: _mailgunDomainController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
onSavePressed: _onSavePressed,
validator: (value) => value.trim().isEmpty
? localization.pleaseEnterAValue
: null,
), ),
], ],
], ],
@ -283,23 +305,24 @@ class _EmailSettingsState extends State<EmailSettings> {
label: localization.fromEmail, label: localization.fromEmail,
controller: _customSendingEmailController, controller: _customSendingEmailController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
onSavePressed: _onSavePressed,
), ),
DecoratedFormField( DecoratedFormField(
label: localization.fromName, label: localization.fromName,
controller: _fromNameController, controller: _fromNameController,
onSavePressed: viewModel.onSavePressed, onSavePressed: _onSavePressed,
keyboardType: TextInputType.name, keyboardType: TextInputType.name,
), ),
DecoratedFormField( DecoratedFormField(
label: localization.replyToEmail, label: localization.replyToEmail,
controller: _replyToEmailController, controller: _replyToEmailController,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
onSavePressed: viewModel.onSavePressed, onSavePressed: _onSavePressed,
), ),
DecoratedFormField( DecoratedFormField(
label: localization.replyToName, label: localization.replyToName,
controller: _replyToNameController, controller: _replyToNameController,
onSavePressed: viewModel.onSavePressed, onSavePressed: _onSavePressed,
keyboardType: TextInputType.name, keyboardType: TextInputType.name,
), ),
DecoratedFormField( DecoratedFormField(
@ -307,7 +330,7 @@ class _EmailSettingsState extends State<EmailSettings> {
controller: _bccEmailController, controller: _bccEmailController,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
hint: localization.commaSeparatedList, hint: localization.commaSeparatedList,
onSavePressed: viewModel.onSavePressed, onSavePressed: _onSavePressed,
), ),
AppDropdownButton<int>( AppDropdownButton<int>(
showBlank: true, showBlank: true,