Skip to content

Added defaultOptions to Multi Select List #86

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KoalaBear
Copy link

The current defaultOption exists on both MultipleSelectList and SelectList while it is only implemented for SelectList.
So I added a defaultOptions variable & implemented it for MultipleSelectList in order to be able to load up a list of previously selected values from my app storage.

@apolloid
Copy link

I had raised a pull request to Koala's repo so as to make the defaultOptions work with save props ('key' or 'value') and also in a format similar to defaultOption in Select. Not sure whether want to keep it as defaultOption too in the MultiSelect instead of defaultOptions

const App = () => {

  const [selected, setSelected] = React.useState([]);
  
  const data = [
    {key:'1',value:'Jammu & Kashmir'},
    {key:'2',value:'Gujrat'},
    {key:'3',value:'Maharashtra'},
    {key:'4',value:'Goa'},
  ]

  return(
    <MultipleSelectList 
      onSelect={() => alert(selected)}
      setSelected={(val) => setSelected(val)} 
      data={data} 
      save="key"
      defaultOptions={[ {key:'1', value:'Jammu & Kashmir' }, {key:'4', value:'Goa' }]}   //default selected options
    />
  )

};

jeremydumais added a commit to jeremydumais/react-native-dropdown-select-list that referenced this pull request Jan 11, 2024
@bohnerjosh
Copy link

As KoalaBear mentioned, I saw that MultipleSelectList has a defaultOptions property, but it is not implemented. I am working on an app right now where this functionality would be very helpful. Please get this reviewed and merge soon. Thanks.

@dayoherrera
Copy link

Hello, I have been using the library and it would be great to have the functionality of sending the default values ​​to the MultiSelectList. Could you please continue with this PR? Thank you @danish1658

@muhammadashfaq
Copy link

+1

@muhammadashfaq
Copy link

@KoalaBear

Please update useEffect with following error.

Error: Objects are not valid as a React child (found: object with keys {key, value}). If you meant to render a collection of children, use an array instead.

React.useEffect(() => {
        if(defaultOptions && _firstRender){
            const defaultValues = defaultOptions.map((option: L1Keys) => option.value);
            setSelected(defaultValues);
            setSelectedVal(defaultValues);
        }
    }, [_firstRender, defaultOptions])

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

Successfully merging this pull request may close these issues.

5 participants