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

Unable to change TextField.value after a FormField.save #245

Closed
canthelou-xyz opened this issue Mar 17, 2020 · 1 comment
Closed

Unable to change TextField.value after a FormField.save #245

canthelou-xyz opened this issue Mar 17, 2020 · 1 comment
Labels
solved A solution for this issue had been found

Comments

@canthelou-xyz
Copy link

Hi,

I need to reset all my form fields even after I "submit" the form...

  1. If I never call onPressSubmitthen I can reset the form.
  2. But as soon as I save the form, it does nothing more than getting initialValues, but those ones are now the values submitted and no more the initial values...
  • Why setAttributeValue does not change the display ?
  • What do I do wrong ?
  • How to reset or set a field value after build ?

Thank you

void onPressSubmit() async {
    setState(() => {err.reset()});
    if (_formKey.currentState.saveAndValidate()) {
      try {
        final data = _formKey.currentState.value;
        final loginProps = LoginModel(
            login: data['login'].toString(),
            password: data['password'].toString());
        final auth = Provider.of<Authentication>(context, listen: false);
        final response = await auth.login(loginProps);
        widget?.onSuccess(context, (response as AuthenticationModel).token);
      } catch (e) {
        setState(() {
          _formKey.currentState.reset();
          _formKey.currentState.setAttributeValue('login', '');
          _formKey.currentState.setAttributeValue('password', '');
          err.message = e?.message as String;
        });
        widget?.onError(context, '', e.message as String);
      }
    }
  }


  _onTapPasswordReminder() {
    _formKey.currentState.reset();
    _formKey.currentState.setAttributeValue('login', '');
    _formKey.currentState.setAttributeValue('password', '');

    setState(() {
      err.reset();
    });
    widget.onTapPasswordReminder();
  }

flutter-form-builder

@danvick
Copy link
Collaborator

danvick commented Mar 27, 2020

Hi @virgule-xyz,
Kindly use a TextEditingController to change clear the form inputs.

@danvick danvick added the solved A solution for this issue had been found label May 7, 2020
@danvick danvick closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved A solution for this issue had been found
Projects
None yet
Development

No branches or pull requests

2 participants