-
Notifications
You must be signed in to change notification settings - Fork 307
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
Chip - Javascript Plugin - autocomplete : how to update state variable #1117
Comments
Can you try See what console logs on |
or <Chip
options={{
onChipAdd: someFn, |
But yes, |
Hi, Thank you for your reply. It logs undefined. Nothing is returned for e.target.value Below is my code and you can run it on Codesandbox :
|
Ok, I managed to get to something, but it's incomplete: foo is an instance of CASH class App extends React.Component {
handleAddCountry = (foo) => {
console.log(foo.text())
};
render() {
return (
<Chip
close={false}
options={{
onChipAdd: this.handleAddCountry,
autocompleteOptions: {
data: {
" France métropolitaine ": null,
" DOM - TOM ": null,
" DOM ": null,
" Afghanistan ": null
}
}
}}
/>
)
}
} |
But yes, ideally |
Thanks ! it works if I want to add a value to the array but then I can't see the chip anymore and can not delete it How can I do the same function for onChipRemove? Do I need to write a onChipSelect function to display the chips and then write a onChipRemove function to remove it ? Here is the code and the Codesandbox
|
Your issue is that in the handler you are calling What you want is to add a "initial" data to the Chip populated from state. This way when you update the state Chip will be re-rendered with those values. <Chip
options={{
data: [{ tag: 'foo' }] // chip will render with 'foo' as a tag
}} |
Let me know how it goes :) |
I'm going to close this as it's not a bug, good luck! |
Hi,
I would like to update a state variable array but I can't figure out how to update on change.
There is not event linked to the Chip.
I have want to change the array "countries", but when I try to link it with the React-materialize Chip, it does not work.
How can I get the event from the chip ? Can you help ?
Thank you
Below is my code also available in CodeSandbox
The text was updated successfully, but these errors were encountered: