joanpablo / reactive_forms

This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular's Reactive Forms
MIT License
469 stars 86 forks source link

[Feature Request] [form group patch errors] #334

Open AlaaEldeenYsr opened 1 year ago

AlaaEldeenYsr commented 1 year ago

Add a method to patch errors

void main(List<String> args) {
  final form = fb.group({
    'name': '',
    'phone': '',
    'identity': '',
    'school_id': '',
    'childs': fb.array([
      {
        "path": '',
        "stage_id": '',
        "gender": '',
      },
    ]),
  });

  final errorsJson = {
    'name': {
      'SERVER_ERROR': {"error": 'please fill the value'}
    },
    'phone': {
      'SERVER_ERROR': {"error": 'please fill the value'}
    },
    'identity': {
      'SERVER_ERROR': {"error": 'please fill the value'}
    },
    'school_id': {
      'SERVER_ERROR': {"error": 'please fill the value'}
    },
    'childs': [
      {
        "path": {
          'SERVER_ERROR': {"error": 'please fill the value'}
        },
        "stage_id": {
          'SERVER_ERROR': {"error": 'please fill the value'}
        },
        "gender": {
          'SERVER_ERROR': {"error": 'please fill the value'}
        },
      },
    ]
  };

  ReactiveFormConfig(
    validationMessages: {
      'SERVER_ERROR': (error) => (error as Map)['error'],
    },
    child: child,
  );

  form.patchErrors(errorsJson);
}
AlaaEldeenYsr commented 1 year ago

@joanpablo any support please