Question
I'm trying to create a multiple select field, but it seems empty out the array when I click on a item.
Update the array when I change selection.
Maybe some specific behaviour for the multiple attribute?
You need to handle the changes to the field yourself. I've updated your code sample here. Take a closer look at line 31 (i.e. the onChange callback).
@ricardobrandao that does seem to work but is not really the best way to do it for such a common case. Wouldn't it be better if something like this was built into Formik as perhaps a separate component?
I agree. It would be great if the multiple select "just work" - as for the simple select.
However, I'm not sure on how to properly address this. I believe that having a separate component is not the best way to go. After a quick look at the code, it seems that we could do something on the Formik's handleChange callback. Nevertheless, @jaredpalmer should be the right person to give you an answer.
I'm currently evaluating Formik - and some other options - to use in my company's app. I've just started doing that yesterday so Formik is kinda new to me.
Yeah there probably needs to be an exception added for the val part to evaluate select cases or something.
Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.
ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it.
I just want to say that I am building my very first form using Formik and I have bumped into this case straight away. If I find that multiple-select-formik problem already has a solution I will post it here. If not, can someone please suggest whether Formik is at present in any stronger position to handle such cases than plain React?
I think the original poster has eventually solved this problem here:
https://codesandbox.io/s/n33qkoy64m
I think the original poster has eventually solved this problem here:
https://codesandbox.io/s/n33qkoy64m
This seems to work well but it based on v0.11.11 of Formik. Has anyone got a working example of implementing multiple select on an up-to-date version of Formik?
Most helpful comment
You need to handle the changes to the field yourself. I've updated your code sample here. Take a closer look at line 31 (i.e. the
onChangecallback).