Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formkey.currentState!.validate() doesn't call FormzInput.validate()? #38

Closed
freewebwithme opened this issue May 4, 2021 · 2 comments
Closed
Assignees

Comments

@freewebwithme
Copy link

Hi!
I have a trouble with validation form fields.
Let's say I have firstName and lastName form field with initial value(from database)
so form input is pre-populated with value.

But I want to change just firstName field and it calls onChanged function.
And onChanged function calls FirstNamChanged bloc event like this

AccountInfoFormState _firstNameChangedToState(
      FirstNameChanged event, AccountInfoFormState state) {
    final firstName = FirstName.dirty(event.firstName);
    return state.copyWith(
      firstName: firstName,
      status: Formz.validate([
        firstName,
        state.lastName,
      ]),
    );
  }

I don't touch lastName field, so onChanged function is not called and so intial state of lastName is empty.
So Formz.validate([firstName, state.lastName]) will return invalidated.

How can I pass intial state to FormzInput ?

And I tried to submit the form with empty value. like this

if(formKey.currentState!.validate()) 

but it returns form is validated
It doesn't seems to call each FormzInputs' validator function

What am I missing?

@alvinvin00
Copy link

alvinvin00 commented Nov 1, 2021

if(formKey.currentState!.validate()) calls validator on each TextFormField inside a Form widget, not Formz. It will return valid everytime if there's no validator on each TextFormField.

I have created an example on my gist : https://dartpad.dev/55c4a7c18e5fb5f6b959b36aec19b64b

@felangel
Copy link
Contributor

Closing for now but feel free to comment with any additional questions and I'm happy to continue the discussion 👍

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

No branches or pull requests

3 participants