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

How to validate only dropdown search field? #732

Open
ffd114 opened this issue Dec 27, 2024 · 6 comments
Open

How to validate only dropdown search field? #732

ffd114 opened this issue Dec 27, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@ffd114
Copy link

ffd114 commented Dec 27, 2024

I run into issue where I need to validate only the dropdown search field, usually when using TextFormField I can just set the key with GlobalKey<FormFieldState>(), but I cannot find the way to do this on dropdown search, is there a way to to validate only the drop down search field?

@salim-lachdhaf
Copy link
Owner

salim-lachdhaf commented Dec 27, 2024

yes, in the same way as the TextFormField .
just add a key to your DropdownSearch like :

final myKey = GlobalKey<DropdownSearchState<T>>();

DropdownSearch<T>(
     key: myKey  ,
     ...
)

then call
myKey.currentState?.validate()

@ffd114
Copy link
Author

ffd114 commented Dec 28, 2024

But DropdownSearchState does not have validate() function, so it throws error on me. Anyway for now I just forked this package and add some access to inner FormField key, even though it is not very clean but for now it's sufficient.

Thanks for this awesome package!

@salim-lachdhaf
Copy link
Owner

Yes, you are right. you can only change validationMode.
But why did not put your DropdownSearch inside a Form and call validate on form that contains your DropdownSearch ?

@salim-lachdhaf salim-lachdhaf added the enhancement New feature or request label Dec 28, 2024
@ffd114
Copy link
Author

ffd114 commented Dec 28, 2024

In my use case, I use DropdownSearch to list foreign currencies, below the DropdownSearch there are text field to fill the exchange rate and a button to fetch the exchange rate from my server. When I click this button, I need to validate only the selected currency from DropdownSearch, if it is valid, it will call the API and the text field will be filled with the data from my server. If I use form valid, it will also check another field unrelated for my API calls

@salim-lachdhaf
Copy link
Owner

salim-lachdhaf commented Dec 28, 2024

no, i meant you create a Form only for DropdownSearch Which will give you a structure like this

Form
--TextFormField1
--TextFormField2
--TextFormField..
--Form <--- to validate only your `DropdownSearch`
----DropdownSearch
--TextFormFieldx
...

@ffd114
Copy link
Author

ffd114 commented Dec 28, 2024

Ahh sorry I misunderstood your question, I haven't tried it that way and did not know if that will works. Thanks for the insight!

But for now even if it works, I think I will stick with the current implementation, since I still need to access the DropdownSearchState key and by using Form key I need to declare another key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants