react-native-dropdown-select-list
react-native-dropdown-select-list copied to clipboard
Added defaultOptions to Multi Select List
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.
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
/>
)
};
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.
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