Closed fehernyul closed 2 years ago
Hi! Validators.compose don't work to this case?
validator: FormBuilderValidators.compose(
[
FormBuilderValidators.email(
context,
),
FormBuilderValidators.required(
context,
),
],
),
Or create a custom validator, like:
static FormFieldValidator<String> iban({
required String ibanErrorText,
}) =>
(valueCandidate) {
if (valueCandidate != null && valueCandidate.isNotEmpty) {
return functionToValidateIban(valueCandidate) ? null : ibanErrorText;
}
return null;
};
Hi,
Yes it works this way, but I need to use via a method. I need to the validator returned from a function. This is a very simple code, I have a bunch of FormBuilderTextField which is generated by a json file. The form is fully generated by the json's content. I don't know in advance what kind of validator it will need. That is what I have to use a function which result a validator list by some extra parameter. I must use a function, and I put in that what I found in the json. minLength, maxLength, minValue, maxValue, minDateTime, maxDateTime, required, ...
Can you help me to write this function? (like in the example I showed)
Thank you!
You can create a dynamic validators with FormBuilderValidators.compose
validator: FormBuilderValidators.compose(
[
if(isInteger)
FormBuilderValidators.minLength(
context,
),
if(String)
FormBuilderValidators.required(
context,
),
],
),
This is works very fine! Thank you!! :)
hallo, can i make a function using await? because my function return Future, in FormBuilderValidators.compose?
hallo, can i make a function using await? because my function return Future, in FormBuilderValidators.compose?
It's a good idea, but this issue was closed. I think you have to create a new one with this question.
Environment
Package name:
flutter_form_builder: ^7.3.1 form_builder_validators: ^8.1.1
Hi there,
Is it possible that case, I have some FormBuilderTextField and I need to validate them with FormFieldValidator lists. I want to get the validators from a function. Some FormBuilderTextField is String type and some are integer, double,, date, ...
This is the code which unfortunately doesn't work:
Form:
The getValidators method:
Can you help me to solve this "getValidators" method please?
It could be the best if I will can add some custom validator too. (related to https://github.com/danvick/flutter_form_builder/issues/1002)
Thank you, Gabor