From ff062f14cb32a21210324ddbb582b1d46a0e72c2 Mon Sep 17 00:00:00 2001 From: Petr Jilek Date: Tue, 8 Oct 2024 09:40:14 +0200 Subject: [PATCH 1/3] Add notBlank validator --- glade_forms/lib/src/validator/string_validator.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/glade_forms/lib/src/validator/string_validator.dart b/glade_forms/lib/src/validator/string_validator.dart index 426a1ba..c0e75fb 100644 --- a/glade_forms/lib/src/validator/string_validator.dart +++ b/glade_forms/lib/src/validator/string_validator.dart @@ -17,6 +17,19 @@ class StringValidator extends GladeValidator { shouldValidate: shouldValidate, ); + /// Given value can't be blank. + void notBlank({ + OnValidateError? devError, + Object? key, + ShouldValidateCallback? shouldValidate, + }) => + satisfy( + (input) => input.trim().isNotEmpty, + devError: devError ?? (_) => "Value can't be empty", + key: key ?? GladeErrorKeys.stringEmpty, + shouldValidate: shouldValidate, + ); + /// Checks that value is valid email address. /// /// Used Regex expression `^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$`. From a85dc640acd59ecffc4266fd0fa92f14ced1e650 Mon Sep 17 00:00:00 2001 From: Petr Jilek Date: Mon, 14 Oct 2024 10:22:22 +0200 Subject: [PATCH 2/3] Add allowBlank into string_validator notEmpty --- .../lib/src/validator/string_validator.dart | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/glade_forms/lib/src/validator/string_validator.dart b/glade_forms/lib/src/validator/string_validator.dart index c0e75fb..63286a4 100644 --- a/glade_forms/lib/src/validator/string_validator.dart +++ b/glade_forms/lib/src/validator/string_validator.dart @@ -9,22 +9,10 @@ class StringValidator extends GladeValidator { OnValidateError? devError, Object? key, ShouldValidateCallback? shouldValidate, + bool allowBlank = true, }) => satisfy( - (input) => input.isNotEmpty, - devError: devError ?? (_) => "Value can't be empty", - key: key ?? GladeErrorKeys.stringEmpty, - shouldValidate: shouldValidate, - ); - - /// Given value can't be blank. - void notBlank({ - OnValidateError? devError, - Object? key, - ShouldValidateCallback? shouldValidate, - }) => - satisfy( - (input) => input.trim().isNotEmpty, + (input) => allowBlank ? input.isNotEmpty : input.trim().isNotEmpty, devError: devError ?? (_) => "Value can't be empty", key: key ?? GladeErrorKeys.stringEmpty, shouldValidate: shouldValidate, From 3bf80be8dafd765bf982742e745c7e142443510c Mon Sep 17 00:00:00 2001 From: Petr Jilek Date: Mon, 14 Oct 2024 10:29:54 +0200 Subject: [PATCH 3/3] Update Changelog --- glade_forms/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/glade_forms/CHANGELOG.md b/glade_forms/CHANGELOG.md index 861bba3..43e6a6f 100644 --- a/glade_forms/CHANGELOG.md +++ b/glade_forms/CHANGELOG.md @@ -1,4 +1,5 @@ ## DEV: +- **[Add]**: Add `allowBlank` parameter to `isEmpty` string validator. - **[Add]**: Add `IntInput` as a specialized variant of GladeInput which has additional, int related, validations such as `isBetween`, `isMin`, `isMax` - **[Add]**: Support skipping particular validation with `shouldValidate` callback. - **[Breaking]**: The `resetToPure` method on both GladeInput and GladeModel has been renamed to `setAsNewPure`. This change better reflects the method's behavior of setting a new pure state rather than resetting to the original state.