Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 11.0.1

- Align between validator input types with other validators
- Split up BaseValidator into TranslatedValidator so only that one needs to provide a translation

## 11.0.0

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ We welcome efforts to internationalize/localize the package by translating the d
#### Add new validator

1. Add a new validator to one of the folders in the `src` folder.
2. Implement it using the `BaseValidator` class. Override the `validateValue` method and let the base class handle the null check in the `validate` method.
3. Override the `translatedErrorText` property and return the correct translation from `FormBuilderLocalizations.current.`.
2. Implement it using the `BaseValidator` or `TranslatedValidator` class. Override the `validateValue` method and let the base class handle the null check in the `validate` method.
3. When using a `TranslatedValidator, Override the `translatedErrorText` property and return the correct translation from `FormBuilderLocalizations.current.`.
4. Make sure to pass `errorText` and `checkNullOrEmpty` to the base class.
5. Add static method to `form_builder_validators.dart` that uses the new validator.
6. Implement tests
Expand Down
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ linter:
always_use_package_imports: false
always_specify_types: true
omit_local_variable_types: false
public_member_api_docs: true
public_member_api_docs: true
directives_ordering: true

1 change: 1 addition & 0 deletions lib/form_builder_validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export 'src/identity/identity.dart';
export 'src/network/network.dart';
export 'src/numeric/numeric.dart';
export 'src/string/string.dart';
export 'src/translated_validator.dart';
export 'src/usecase/usecase.dart';
216 changes: 206 additions & 10 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,89 @@
"dateStringErrorText": "This field requires a valid date string.",
"emailErrorText": "This field requires a valid email address.",
"equalErrorText": "This field value must be equal to {value}.",
"equalLengthErrorText": "Value must have a length equal to {length}",
"@equalErrorText": {
"placeholders": {
"value": {
"type": "String",
"description": "The value that the field must equal"
}
}
},
"equalLengthErrorText": "Value must have a length equal to {length}.",
"@equalLengthErrorText": {
"placeholders": {
"length": {
"type": "int",
"description": "The exact length the value must have"
}
}
},
"integerErrorText": "This field requires a valid integer.",
"ipErrorText": "This field requires a valid IP.",
"matchErrorText": "Value does not match pattern.",
"maxErrorText": "Value must be less than or equal to {max}",
"maxLengthErrorText": "Value must have a length less than or equal to {maxLength}",
"maxWordsCountErrorText": "Value must have a words count less than or equal to {maxWordsCount}",
"minErrorText": "Value must be greater than or equal to {min}",
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}",
"minWordsCountErrorText": "Value must have a words count greater than or equal to {minWordsCount}",
"maxErrorText": "Value must be less than or equal to {max}.",
"@maxErrorText": {
"placeholders": {
"max": {
"type": "num",
"description": "The maximum value allowed"
}
}
},
"maxLengthErrorText": "Value must have a length less than or equal to {maxLength}.",
"@maxLengthErrorText": {
"placeholders": {
"maxLength": {
"type": "int",
"description": "The maximum length allowed"
}
}
},
"maxWordsCountErrorText": "Value must have a words count less than or equal to {maxWordsCount}.",
"@maxWordsCountErrorText": {
"placeholders": {
"maxWordsCount": {
"type": "int",
"description": "The maximum word count allowed"
}
}
},
"minErrorText": "Value must be greater than or equal to {min}.",
"@minErrorText": {
"placeholders": {
"min": {
"type": "num",
"description": "The minimum value allowed"
}
}
},
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}.",
"@minLengthErrorText": {
"placeholders": {
"minLength": {
"type": "int",
"description": "The minimum length required"
}
}
},
"minWordsCountErrorText": "Value must have a words count greater than or equal to {minWordsCount}.",
"@minWordsCountErrorText": {
"placeholders": {
"minWordsCount": {
"type": "int",
"description": "The minimum word count required"
}
}
},
"notEqualErrorText": "This field value must not be equal to {value}.",
"@notEqualErrorText": {
"placeholders": {
"value": {
"type": "String",
"description": "The value that the field must not equal"
}
}
},
"numericErrorText": "Value must be numeric.",
"requiredErrorText": "This field cannot be empty.",
"urlErrorText": "This field requires a valid URL address.",
Expand All @@ -23,17 +95,93 @@
"creditCardExpiredErrorText": "This credit card has expired.",
"creditCardCVCErrorText": "This field requires a valid CVC code.",
"colorCodeErrorText": "Value should be a valid {colorCode} color code.",
"@colorCodeErrorText": {
"placeholders": {
"colorCode": {
"type": "String",
"description": "The type of color code (e.g., HEX, RGB)"
}
}
},
"uppercaseErrorText": "Value must be uppercase.",
"lowercaseErrorText": "Value must be lowercase.",
"fileExtensionErrorText": "File extension must be {extensions}",
"fileSizeErrorText": "File size must be less than {maxSize} while it is {fileSize}",
"dateRangeErrorText": "Date must be in range {min} - {max}",
"fileExtensionErrorText": "File extension must be {extensions}.",
"@fileExtensionErrorText": {
"placeholders": {
"extensions": {
"type": "String",
"description": "Allowed file extensions"
}
}
},
"fileSizeErrorText": "File size must be less than {maxSize} while it is {fileSize}.",
"@fileSizeErrorText": {
"placeholders": {
"maxSize": {
"type": "String",
"description": "The maximum file size allowed"
},
"fileSize": {
"type": "String",
"description": "The actual file size"
}
}
},
"dateRangeErrorText": "Date must be in range {min} - {max}.",
"@dateRangeErrorText": {
"placeholders": {
"min": {
"type": "DateTime",
"format": "yMd",
"example": "11/10/2021",
"description": "The minimum date allowed"
},
"max": {
"type": "DateTime",
"format": "yMd",
"example": "11/10/2021",
"description": "The maximum date allowed"
}
}
},
"mustBeTrueErrorText": "This field must be true.",
"mustBeFalseErrorText": "This field must be false.",
"containsSpecialCharErrorText": "Value must contain at least {min} special characters.",
"@containsSpecialCharErrorText": {
"placeholders": {
"min": {
"type": "int",
"description": "The minimum number of special characters required"
}
}
},
"containsUppercaseCharErrorText": "Value must contain at least {min} uppercase characters.",
"@containsUppercaseCharErrorText": {
"placeholders": {
"min": {
"type": "int",
"description": "The minimum number of uppercase characters required"
}
}
},
"containsLowercaseCharErrorText": "Value must contain at least {min} lowercase characters.",
"@containsLowercaseCharErrorText": {
"placeholders": {
"min": {
"type": "int",
"description": "The minimum number of lowercase characters required"
}
}
},
"containsNumberErrorText": "Value must contain at least {min} numbers.",
"@containsNumberErrorText": {
"placeholders": {
"min": {
"type": "int",
"description": "The minimum number of numerical characters required"
}
}
},
"alphabeticalErrorText": "Value must be alphabetical.",
"uuidErrorText": "Value must be a valid UUID.",
"jsonErrorText": "Value must be valid JSON.",
Expand All @@ -44,11 +192,59 @@
"oddNumberErrorText": "Value must be an odd number.",
"evenNumberErrorText": "Value must be an even number.",
"portNumberErrorText": "Value must be a valid port number between {min} and {max}.",
"@portNumberErrorText": {
"placeholders": {
"min": {
"type": "int",
"description": "The minimum port number allowed"
},
"max": {
"type": "int",
"description": "The maximum port number allowed"
}
}
},
"macAddressErrorText": "Value must be a valid MAC address.",
"startsWithErrorText": "Value must start with {value}.",
"@startsWithErrorText": {
"placeholders": {
"value": {
"type": "String",
"description": "The value that the field must start with"
}
}
},
"endsWithErrorText": "Value must end with {value}.",
"@endsWithErrorText": {
"placeholders": {
"value": {
"type": "String",
"description": "The value that the field must end with"
}
}
},
"containsErrorText": "Value must contain {value}.",
"@containsErrorText": {
"placeholders": {
"value": {
"type": "String",
"description": "The value that the field must contain"
}
}
},
"betweenErrorText": "Value must be between {min} and {max}.",
"@betweenErrorText": {
"placeholders": {
"min": {
"type": "num",
"description": "The minimum value allowed"
},
"max": {
"type": "num",
"description": "The maximum value allowed"
}
}
},
"containsElementErrorText": "Value must be in list.",
"ibanErrorText": "Value must be a valid IBAN.",
"uniqueErrorText": "Value must be unique.",
Expand Down
5 changes: 1 addition & 4 deletions lib/src/base_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ abstract class BaseValidator<T> {
/// {@template base_validator_error_text}
/// The error message returned if the value is invalid.
/// {@endtemplate}
String get errorText => _errorText ?? translatedErrorText;

/// The translated error message returned if the value is invalid.
String get translatedErrorText;
String? get errorText => _errorText;

/// {@template base_validator_null_check}
/// Whether to check if the value is null or empty.
Expand Down
7 changes: 3 additions & 4 deletions lib/src/bool/has_lowercase_chars_validator.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import '../../localization/l10n.dart';
import '../base_validator.dart';
import '../../form_builder_validators.dart';

/// {@template has_lowercase_chars_template}
/// [HasLowercaseCharsValidator] extends [BaseValidator] to validate if a string
/// [HasLowercaseCharsValidator] extends [TranslatedValidator] to validate if a string
/// contains a specified minimum number of lowercase characters.
///
/// ## Parameters:
Expand All @@ -13,7 +12,7 @@ import '../base_validator.dart';
///
/// {@macro lower_case_template}
/// {@endtemplate}
class HasLowercaseCharsValidator extends BaseValidator<String> {
class HasLowercaseCharsValidator extends TranslatedValidator<String> {
/// Constructor for the lowercase characters validator.
HasLowercaseCharsValidator({
this.atLeast = 1,
Expand Down
7 changes: 3 additions & 4 deletions lib/src/bool/has_numeric_chars_validator.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import '../../localization/l10n.dart';
import '../base_validator.dart';
import '../../form_builder_validators.dart';

/// {@template has_numeric_chars_template}
/// [HasNumericCharsValidator] extends [BaseValidator] to validate if a string
/// [HasNumericCharsValidator] extends [TranslatedValidator] to validate if a string
/// contains a specified minimum number of numeric characters (digits).
///
/// ## Parameters:
Expand All @@ -13,7 +12,7 @@ import '../base_validator.dart';
///
/// {@macro numeric_chars_template}
/// {@endtemplate}
class HasNumericCharsValidator extends BaseValidator<String> {
class HasNumericCharsValidator extends TranslatedValidator<String> {
/// Constructor for the numeric characters validator.
HasNumericCharsValidator({
this.atLeast = 1,
Expand Down
7 changes: 3 additions & 4 deletions lib/src/bool/has_special_chars_validator.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import '../../localization/l10n.dart';
import '../base_validator.dart';
import '../../form_builder_validators.dart';

/// {@template has_special_chars_template}
/// [HasSpecialCharsValidator] extends [BaseValidator] to validate if a string
/// [HasSpecialCharsValidator] extends [TranslatedValidator] to validate if a string
/// contains a specified minimum number of special characters.
///
/// ## Parameters:
Expand All @@ -13,7 +12,7 @@ import '../base_validator.dart';
///
/// {@macro special_chars_template}
/// {@endtemplate}
class HasSpecialCharsValidator extends BaseValidator<String> {
class HasSpecialCharsValidator extends TranslatedValidator<String> {
/// Constructor for the special characters validator.
HasSpecialCharsValidator({
this.atLeast = 1,
Expand Down
7 changes: 3 additions & 4 deletions lib/src/bool/has_uppercase_chars_validator.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import '../../localization/l10n.dart';
import '../base_validator.dart';
import '../../form_builder_validators.dart';

/// {@template has_uppercase_chars_template}
/// [HasUppercaseCharsValidator] extends [BaseValidator] to validate if a string
/// [HasUppercaseCharsValidator] extends [TranslatedValidator] to validate if a string
/// contains a specified minimum number of uppercase characters.
///
/// ## Parameters:
Expand All @@ -13,7 +12,7 @@ import '../base_validator.dart';
///
/// {@macro upper_case_template}
/// {@endtemplate}
class HasUppercaseCharsValidator extends BaseValidator<String> {
class HasUppercaseCharsValidator extends TranslatedValidator<String> {
/// Constructor for the uppercase characters validator.
HasUppercaseCharsValidator({
this.atLeast = 1,
Expand Down
Loading