Stacked-Org/stacked

[feature]: Overall form validator

bdairy opened this issue · 2 comments

bdairy commented

Is your feature request related to a problem? Please describe.

I have a form with two optional fields, but the use should fill at least one field,, for example , Email address or Mobile number..

I have email and mobile regex validators,, but the form wont be valid until one value is filled and valid,,

We need a custom form validator.

Describe the solution you would like

My suggestion is to add a validator field to the form.. like this

@FormView(
  fields: [
    FormTextField(
      name: 'mobile',
      initialValue: null,
      validator: FormValidator.validateMobile,
    ),
    FormTextField(
      name: 'email',
      initialValue: null,
      validator: FormValidator.validateEmail,
    ),
  ],
validator: FormValidator.validateForm /// This should accept a map of the field values.. 
)

You can get the idea from the Reactive Forms of angular...

Additional Context

No response

@bdairy I will add this as a potencial new feature but in the meantime I think you can do something like below:

CustomFormViewModel

Future<void> saveUser() async {
  if (hasEmailValidationMessage && hasMobileValidationMessage) return;

  // do your task here...
}
bdairy commented

@bdairy I will add this as a potencial new feature but in the meantime I think you can do something like below:

CustomFormViewModel

Future<void> saveUser() async {

  if (hasEmailValidationMessage && hasMobileValidationMessage) return;

  // do your task here...

}

Already created a custom validator function for that form, I appreciate you guys for considering our requests.

Best of luck