react-native-dropdown-select-list icon indicating copy to clipboard operation
react-native-dropdown-select-list copied to clipboard

How can i set initial values selected?

Open Gugarauj07 opened this issue 10 months ago • 6 comments

In my profile page, i want to display in the dropdown the previously variables selected by the user.

Gugarauj07 avatar Aug 26 '23 02:08 Gugarauj07

you can use defaultOption

LucasCoelho avatar Sep 14 '23 14:09 LucasCoelho

you can use defaultOption

export default function App() {

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

  return(
    <MultipleSelectList 
        setSelected={(val) => setSelected(val)} 
        data={data} 
        save="value"
        onSelect={() => alert(selected)} 
        label="Categories"
        defaultOption={{ key:'1', value:'Jammu & Kashmir' }}   //default selected option
    />
  )
}

I tryed using it like this, but there is no default variable selected.

Gugarauj07 avatar Sep 29 '23 05:09 Gugarauj07

you can use defaultOption

export default function App() {

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

  return(
    <MultipleSelectList 
        setSelected={(val) => setSelected(val)} 
        data={data} 
        save="value"
        onSelect={() => alert(selected)} 
        label="Categories"
        defaultOption={{ key:'1', value:'Jammu & Kashmir' }}   //default selected option
    />
  )
}

I tryed using it like this, but there is no default variable selected.

yeah, me too

alveentino avatar Oct 23 '23 02:10 alveentino

In my case adding defaultOption makes it unable to change value onSelect.

xgenem avatar Oct 27 '23 16:10 xgenem

Same for me. When a checkbox is ticked, I assume it is stored in a state? The documentation details the properties of setSelected but not the state. Is there a possibility to have multiple default selected values? I can collaborate on that

bastos12 avatar Nov 18 '23 13:11 bastos12

i have same issue. the option is not selected.

edit: nevermind i got it working, defaultOption={{key: text, value: text}}

natsu90 avatar Jan 11 '24 15:01 natsu90