Aidurber / react-picky

Yet another React multiselect. With checkbox support instead of tags.
MIT License
79 stars 35 forks source link

Need custom data onChange of value #105

Closed Puneetbh closed 5 years ago

Puneetbh commented 5 years ago

I am using react-picky in loop and displaying multiple dropdowns using package, my requirement is i need custom data onChange of value so i can use it to make generic handleOnChange method. Please suggest how can i get custom data related to dropdown

Aidurber commented 5 years ago

@Puneetbh I'll need an example, I don't get what you mean.

Puneetbh commented 5 years ago

@Aidurber I have array of objects and with loop i am displaying react-picky dropdown by passing options, now i am passing common generic onchange method to in onChange property, inside that i want to know which dropdon valud changed so i can update state accordingly

Like if country changed by user i want to know user changed country then i will update state of country so want to get some additional data whenever user making selection in dropdown Basically i want to know which dropdon onChange method invoked

Puneetbh commented 5 years ago

@Aidurber i got the solution, Thanks

priyankaviswan commented 5 years ago

Hi Aidurber,

I have recently downloaded the picky and have used it inside a map function to loop through my dynamic data. In the picky i have set multiselect as true. How ever on the onchange function am getting only the currently selected value and not the list of values selected for picky.

This is the sample code: { sectorsData.map((selectItem, i) => (

))} in the on change function i have written the following code : const selectedOption = (name,value) =>{ setAssetsAddedState(prev => { return { ...prev, [name] : value}}); } The issue am facing is in the case of multiselect where the value will be a single object containing the current selected item rather than the list of items selected. Could you please help me with the issue. I have tried every possible solution and it does not seem to work.Any help would be really appreciated as am stuck in the issue for sometime. Where a sample sectorsData: [ { "name": "Technology", "options": [ { "id": "1", "name": "AI & Analytics" }, { "id": "2", "name": "Robotics" }, { "id": "3", "name": "IoT" } ] }, { "name": "Sector", "options": [ { "id": "1", "name": "Automotive" }, { "id": "2", "name": "Oil and gas" } ] } ]