Giter Club home page Giter Club logo

Comments (6)

danvick avatar danvick commented on May 12, 2024

Ooh yeah. The fields have an attribute named validators which takes a list of FormFieldValidators. That makes validators composable and reusable. There is a class named FormBuilderValidators with all the common validators but you can definitely include your own custom validator.
Checkout the v3 example (on pub).
Sample Usage:

FormBuilderTextField(
    attribute: "age",
    decoration: InputDecoration(labelText: "Age"),
    validators: [
        FormBuilderValidators.numeric(),
        FormBuilderValidators.max(70)
        FormBuilderValidators.min(18, errorText: "You can't be under 18.")
    ],
),

P.S. I'm currently working on comprehensive documentation.

from flutter_form_builder.

jasonlaw avatar jasonlaw commented on May 12, 2024

That means we can create our own customized FormBuilderValidator right?

from flutter_form_builder.

danvick avatar danvick commented on May 12, 2024

Sure. Or alternatively just stick in your validator function inside the list of validators, like so:

FormBuilderTextField(
    attribute: "over_18",
    decoration: InputDecoration(labelText: "Are you over 18?"),
    validators: [
        FormBuilderValidators.required(),
        (val){
            if(val != "Yes")
                return "The answer must be Yes";
        },
    ],
),

from flutter_form_builder.

danvick avatar danvick commented on May 12, 2024

The validator function just has to be of type FormFieldValidator from Flutter. The reason for making it this way - in a list - is to allow you to define your custom validator once and just use it in different fields or even across multiple forms / pages.

from flutter_form_builder.

jasonlaw avatar jasonlaw commented on May 12, 2024

I see, that's cool....great job! Thank you very much!

from flutter_form_builder.

danvick avatar danvick commented on May 12, 2024

I'm glad you appreciate it.

from flutter_form_builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.