feat nested_form_builder.dart add NestedFormBuilder;#1156
feat nested_form_builder.dart add NestedFormBuilder;#1156Hu-Wentao wants to merge 4 commits intoflutter-form-builder-ecosystem:mainfrom
Conversation
feat nested_form.dart NestedForm add NestedFormBuilder Demo
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1156 +/- ##
==========================================
- Coverage 84.93% 82.22% -2.72%
==========================================
Files 19 20 +1
Lines 697 720 +23
==========================================
Hits 592 592
- Misses 105 128 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I just came to issues looking for a way to nest forms, appreciate this! |
| ], | ||
| supportedLocales: FormBuilderLocalizations.delegate.supportedLocales, | ||
| home: const CompleteForm(), | ||
| // supportedLocales: FormBuilderLocalizations.delegate.supportedLocales, |
There was a problem hiding this comment.
Please replace this line with language config, like this:
supportedLocales: [
Locale('de'),
Locale('en'),
Locale('es'),
Locale('fr'),
Locale('it'),
...
],|
Thanks a lot for this contribution! Will be a big step foward to improve this package. |
|
Hi, I have been testing this new feature (it's awesome btw, thanks for the PR) and I was wondering how validation will work? For me right now, validating the parent/main form didn't trigger validation on the nested/child fields. |
|
I got the nested form validation to work for me by adding a validator to the FormBuilderField of NestedFormBuilder, like so: @override
Widget build(BuildContext context) => FormBuilderField<Map<String, dynamic>>(
name: name,
initialValue:
parentFormKey?.currentState?.initialValue[name] ?? initialValue,
valueTransformer: valueTransformer ?? (_) => _,
onReset: () => formKey.currentState?.reset(),
// Added validator here
validator: (_) =>
(formKey.currentState?.validate() ?? false) ? null : '',
builder: (field) => FormBuilder(
key: formKey,
initialValue: field.value ?? {},
onChanged: () {
final st = formKey.currentState;
if (st == null) return;
st.save();
field.didChange(valueTransformer?.call(st.value) ?? st.value);
},
autovalidateMode: autovalidateMode,
onWillPop: onWillPop,
skipDisabled: skipDisabled,
enabled: enabled,
autoFocusOnValidationFailure: autoFocusOnValidationFailure,
clearValueOnUnregister: clearValueOnUnregister,
child: child,
),
); |
|
Something else worth noting, I had to add autovalidateMode: autovalidateMode,just below the new validator, otherwise the nested form was validating on every change. Previously the autovalidateMode was only being passed to the FormBuilder and not the FormBuilderField component |
|
Any update on this? This is such a game changer that is desperately needed. |
|
Ready for nested forms 👍 |
|
any update on this ? |
|
It doesn't seem to solve all use cases, for example, if I have a nested list, {
"foo": "foo value0",
"inner": [
{
"bar": "bar value1",
"baz": "baz value2"
},
{
"bar": "bar value1",
"baz": "baz value2"
}
]
} |
|
any updates? |
@mustafamasri1 can follow the new features here: #1466 |
Add NestedFormBuilder and some example code
resolve issue #239 and #1117
{ "foo": "foo value0", "inner": { "bar": "bar value1", "baz": "baz value2", } }