toystars / react-native-multiple-select

Simple multi-select component for react-native
MIT License
565 stars 313 forks source link

On Submit do custom function #115

Open patrinoua opened 5 years ago

patrinoua commented 5 years ago

Issue summary

After I select the items and press "Submit" I want to make an API call. Is this possible?

Thanks in advance!

iledzka commented 4 years ago

I was looking for the same functionality and it looks like this is not supported. Annoyingly the submit button in multi select doesn't even submit all items (doesn't trigger onSelectedItemsChange), as it is described in the documentation. At the moment the submit button only toggles the dropdown and resets the search term. You would need to change the source or use a hack like this one:

ref={component => {
              this.multiSelect = component;
              if (this.multiSelect) {
                this.multiSelect._submitSelection = () => {
                  console.log('Getting here.. you can add your stuff');
                  this.multiSelect._toggleSelector();
                  // reset searchTerm
                  this.multiSelect._clearSearchTerm();
                };
              }
            }}