Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat nested_form_builder.dart add NestedFormBuilder; #1156

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

Open
Hu-Wentao wants to merge 4 commits into flutter-form-builder-ecosystem:main
base: main
Choose a base branch
Loading
from Hu-Wentao:main

Conversation

@Hu-Wentao
Copy link
Contributor

@Hu-Wentao Hu-Wentao commented Nov 25, 2022
edited
Loading

Add NestedFormBuilder and some example code

resolve issue #239 and #1117

{
 "foo": "foo value0",
 "inner": {
 "bar": "bar value1",
 "baz": "baz value2",
 }
}
 FormBuilder(
 key: formKey,
 initialValue: const {
 'foo': 'foo value0',
 'inner': {
 'bar': 'bar value1',
 'baz': 'baz value2',
 }
 },
 child: Column(
 children: [
 FormBuilderTextField(name: 'foo'),
 Padding(
 padding: const EdgeInsets.only(left: 16.0),
 child: NestedFormBuilder(
 name: 'inner',
 child: Column(
 children: [
 FormBuilderTextField(name: 'bar'),
 FormBuilderTextField(name: 'baz'),
 ],
 )),
 )
 ],
 )),

WilliamCunhaCardoso, k-ane, dJani97, Antoniozinchenko, and VinhNgT reacted with thumbs up emoji deandreamatias, dbadrian, SeongBrave, dJani97, RizanPSTU, and Antoniozinchenko reacted with rocket emoji
Copy link

codecov bot commented Nov 26, 2022
edited
Loading

Codecov Report

❌ Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.22%. Comparing base (76be651) to head (e4d1d45).
⚠️ Report is 423 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/nested_form_builder.dart 0.00% 23 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

ozayr commented Nov 26, 2022
edited
Loading

I just came to issues looking for a way to nest forms, appreciate this!

Hu-Wentao reacted with laugh emoji

Copy link
Collaborator

@deandreamatias deandreamatias left a comment
edited
Loading

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

WilliamCunhaCardoso reacted with thumbs up emoji
],
supportedLocales: FormBuilderLocalizations.delegate.supportedLocales,
home: const CompleteForm(),
// supportedLocales: FormBuilderLocalizations.delegate.supportedLocales,
Copy link
Collaborator

@deandreamatias deandreamatias Nov 27, 2022

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'),
 ...
 ],

Copy link
Collaborator

Thanks a lot for this contribution! Will be a big step foward to improve this package.
Because this is a new important feature, required some changes to can be stable and easy to use for all

Hu-Wentao reacted with hooray emoji

Copy link

k-ane commented Jan 7, 2023

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.

Copy link

k-ane commented Jan 7, 2023

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,
 ),
 );

Copy link

k-ane commented Jan 8, 2023

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

deandreamatias reacted with thumbs up emoji

Copy link

mfizz1 commented Aug 25, 2023

Any update on this? This is such a game changer that is desperately needed.

LucasAlessio and ImReyon reacted with eyes emoji

Copy link

Ready for nested forms 👍

Copy link

any update on this ?

Copy link

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"
 }
 ]
}

Copy link

any updates?

deandreamatias reacted with thumbs down emoji

Copy link
Collaborator

any updates?

@mustafamasri1 can follow the new features here: #1466
Also, can support the package development here: https://opencollective.com/flutter-form-builder-ecosystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@deandreamatias deandreamatias deandreamatias requested changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /