Skip to content

Conversation

@MatteMirror
Copy link

Added getter errorMessages to reactive_form_field.dart

Connection with Issues

Solution Description

The errorMessages getter has been implemented to retrieve a list of all error messages (in addition to the errorText getter, which only returns the first) associated with the FormControl bound to the widget. Here’s a detailed breakdown of the solution:

  • Error Condition: The getter checks if the control has errors and if the _showErrors flag is true.
  • If the 'required' error is present, the method returns a list containing the 'required' error message.
  • The error message is either a custom validation message (if provided) or the string 'required'.

Handling Other Errors:

  • If the 'required' error is not present, the method returns a list of all other error messages.
  • For each error key, it looks for a custom validation message.
  • If a custom validation message is found, it is used as the error message. Otherwise, the error key itself is used as the error message.
  • No Errors or Flag False: If the control has no errors or the _showErrors flag is false, an empty list is returned.

Result

This getter provides more extensive customization options for custom ReactiveTextFields.

List<String> get errorMessages {
if (control.hasErrors && _showErrors) {
// Check if 'required' error is present
if (control.errors.containsKey('required')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to have this tricky behavior bound to hardcoded required key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants