-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
feat nested_form_builder.dart add NestedFormBuilder; #1156
base: main
Are you sure you want to change the base?
Conversation
feat nested_form.dart NestedForm add NestedFormBuilder Demo
Codecov ReportAttention: 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. |
I just came to issues looking for a way to nest forms, appreciate this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 more things to review:
- Revert pubspec.lock changes
- Add tests (can be minimal) to NestedFromBuilder
- Add how use nested builder to README.md
FormBuilderLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
supportedLocales: FormBuilderLocalizations.delegate.supportedLocales, | ||
home: const CompleteForm(), | ||
// supportedLocales: FormBuilderLocalizations.delegate.supportedLocales, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"
}
]
} |
Add NestedFormBuilder and some example code
resolve issue #239 and #1117