Skip to content
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

Is there a way to check dropdown attribute selected value on change? #2

Closed
ckildgypmk opened this issue Nov 6, 2018 · 9 comments
Closed

Comments

@ckildgypmk
Copy link

No description provided.

@danvick
Copy link
Collaborator

danvick commented Nov 6, 2018

Not currently.
Could you kindly suggest the possible application/need for this behaviour.

@ckildgypmk
Copy link
Author

For example I use dropdown menu to display regions that i get from api, when user selected his region I'm getting available city's in that region.

@danvick
Copy link
Collaborator

danvick commented Nov 6, 2018

Hmmm. That would be quite helpful. I'll be willing to start planning for it in near-future releases

@ryanhz
Copy link

ryanhz commented Dec 14, 2018

@danvick Please add formData as parameter in onChanged() callback, so we can check if value change?

instead of:
@OverRide
Widget build(BuildContext context) {
return Form(
key: _formKey,
onChanged: widget.onChanged,

do this:
@OverRide
Widget build(BuildContext context) {
return Form(
key: _formKey,
onChanged: () { widget.onChanged(formData) },

@danvick
Copy link
Collaborator

danvick commented Dec 15, 2018

Thanks @huzhiren. You're the best.

Requires _formKey.currentState.save(); first though

@ryanhz
Copy link

ryanhz commented Dec 16, 2018

Awesome, thanks.

@danvick
Copy link
Collaborator

danvick commented Dec 17, 2018

@ckildgypmk I'm aware that the current solution may not fully solve the problem but we'll have an onChanged() function attached to each FormInput in the coming releases so that one can react to only the changes one is interested in.

@ryanhz
Copy link

ryanhz commented Dec 20, 2018

Yes, when you try to dynamically update the dropdown options when the other filed changed, I got his error, weird:

Error caught by widgets library, thrown building FormField-[<'followupTask'>](dirty, state: FormFieldState#01d28).
'package:flutter/src/material/dropdown.dart': Failed assertion: line 514 pos 15: 'items == null || value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1': is not true.
#2 new DropdownButton (package:flutter/src/material/dropdown.dart:514:15)
#3 _FormBuilderState.formControlsToForm. (package:flutter_form_builder/src/form_builder.dart:244:24)
#4 FormFieldState.build (package:flutter/src/widgets/form.dart)
#5 StatefulElement.build (package:flutter/src/widgets/framework.dart:3787:27)

@danvick
Copy link
Collaborator

danvick commented Apr 30, 2019

As of version 3.0.0, each field has an onChanged callback.

@danvick danvick closed this as completed Apr 30, 2019
deandreamatias pushed a commit that referenced this issue Jun 23, 2024
fix: respecting initial value from formbuilder map when field misses initial value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants