Skip to content

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