Comments (6)
Ooh yeah. The fields have an attribute named validators
which takes a list of FormFieldValidator
s. 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.
That means we can create our own customized FormBuilderValidator right?
from flutter_form_builder.
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.
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.
I see, that's cool....great job! Thank you very much!
from flutter_form_builder.
I'm glad you appreciate it.
from flutter_form_builder.
Related Issues (20)
- When using globalKey.currentState?.saveAndValidate to save and validate a form, a date picker will pop up. HOT 4
- [FormBuilderDateTimePicker]: onPressed of suffixIcon don't work on Windows / Web HOT 1
- [FormBuilderRangeSlider]: Add maxRange value
- No named parameter with the name 'onPopInvoked' HOT 9
- State dos not contain all fields HOT 1
- [Field name or General]: FormBuilderDropdown silently ignores an unknown initialValue
- Resetting form shows error messages HOT 1
- Reuse same widget causes child form field to be overwritten
- [FormBuilderRadioGroup]: No way to decrease padding of Radio widget HOT 4
- [FormBuilderDateTimePicker]: Got problem if initialDate is null and lastDate is years ago.
- [FormBuilderTextField]: Cannot swith to chinese keyborad with keyboardType: TextInputType.text HOT 5
- Internal field 'isDirty' flag is reset too late.
- FormBuilderDropdown onChanged fires twice during form Reset HOT 1
- FormBuilderDropdown when selected keeps triggering a rebuild HOT 1
- [Documentation] RaisedButton is removed.
- [FormBuilderTextField]: TextInputType.emailAddress - not working
- [FormBuilderTextField]: Cannot type the latin text (Vietnamese) on Android HOT 4
- [General]: Add support for lists with multiple fields in each item HOT 1
- [Localizations]: Language code fow Swedish is wrong HOT 1
- [FormBuilderTextField]: Can we add canRequestFocus
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_form_builder.