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

A validator of type Future #15

Open
lambasoft opened this issue Oct 13, 2020 · 11 comments
Open

A validator of type Future #15

lambasoft opened this issue Oct 13, 2020 · 11 comments
Labels
feature A new feature or request p2 Important issues not at the top of the work list

Comments

@lambasoft
Copy link

lambasoft commented Oct 13, 2020

Hello,

I'm trying to use Formz to validate a phonenumber using the https://pub.dev/packages/libphonenumber library.

But libphonenumber's validation function returns a Future, so I was unable to use it in the validator() function of Formz

import 'package:formz/formz.dart';
import 'package:libphonenumber/libphonenumber.dart';

enum PhoneNumberValidationError { invalid }

class PhoneNumber extends FormzInput<String, PhoneNumberValidationError> {
  const PhoneNumber.pure() : super.pure('');

  const PhoneNumber.dirty([String value = '']) : super.dirty(value);

  static final _phoneNumberRegex = RegExp(r'^[+]{1}[0-9]{1,4}[-\s\./0-9]*$');

  @override
  PhoneNumberValidationError validator(String value) {
    return PhoneNumberUtil.isValidPhoneNumber(phoneNumber: "", isoCode: 'US').then((value){
      return null;
    });
  }
}

error: A value of type 'Future<Null>' can't be returned from method 'validator' because it has a return type of 'PhoneNumberValidationError'. (return_of_invalid_type at [datoraid] lib/models/phone_number.dart:16)

@felangel felangel added the feature A new feature or request label Oct 15, 2020
@aakarshbaiju
Copy link

Not entirely sure if this falls into the same use case, but I think this would be great too for scenarios involving asynchronous validation of fields.

@ananthu-confianz
Copy link

+1

1 similar comment
@Tedsterh
Copy link

+1

@Prn-Ice
Copy link

Prn-Ice commented Feb 12, 2022

+1

@JeffyLo94
Copy link

JeffyLo94 commented Apr 15, 2022

@felangel any update on this? It seems to me the simplest solution would necessitate rewriting Formz to include async validation functions.

@raulmabe
Copy link

raulmabe commented May 23, 2022

I'd propose changing the return type to FutureOr<T>? Following the previous example:

Previously

@override
  PhoneNumberValidationError validator(String value) {
    return PhoneNumberUtil.isValidPhoneNumber(phoneNumber: "", isoCode: 'US').then((value){
      return null;
    });
  }

After

@override
 FutureOr<PhoneNumberValidationError> validator(String value)  async {
    return PhoneNumberUtil.isValidPhoneNumber(phoneNumber: "", isoCode: 'US');
  }

And add validating or loading to FormzSubmissionStatus enum

@jmsandiegoo
Copy link

jmsandiegoo commented Jun 20, 2023

+1 ! Are there any workarounds to do async validations?

@Firman95
Copy link

Firman95 commented Jan 8, 2024

Looking at the PR discussion, it seems like there will be no async validation in the future. This is a deal breaker. In most real production application, there must be a use case for async valdiation.

@alestiago
Copy link
Contributor

@Firman95 we are open to work on async validation for Formz. I'm aware that this is a valuable feature for production applications. We want to make sure that when doing so users that will only rely on synchronous validation are not hindered.

If you want this to happen drop a 👍 on the issue, stay tuned!

@MiniSuperDev
Copy link

@alestiago Hello, any update on this?
Thanks

@alestiago alestiago moved this from Backlog to Needs Triage in VGV Open Source 🦄 🧙🌟 Apr 8, 2024
@alestiago
Copy link
Contributor

alestiago commented Apr 8, 2024

Hi @MiniSuperDev not so far. We haven't committed to this work yet (it's a P2), but since it has a decent number of 👍 , I'm moving it to triage so we can re-prioritise this.

@tomarra tomarra moved this from Needs Triage to Todo in VGV Open Source 🦄 🧙🌟 Apr 15, 2024
@tomarra tomarra added the p2 Important issues not at the top of the work list label Apr 15, 2024
@tomarra tomarra moved this from Todo to Backlog in VGV Open Source 🦄 🧙🌟 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request p2 Important issues not at the top of the work list
Projects
Status: Backlog
Development

No branches or pull requests