-
Notifications
You must be signed in to change notification settings - Fork 234
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
Handling many tagsinput #175
Comments
Each individual input needs to have an Array as its value. In the single input example that's
Here's the important parts of what I've done: class Form extends React.Component {
constructor(props) {
this.handleChange = this.handleChange.bind(this);
this.state = {
tags: {} // Store an object instead of `[]`
}
}
handleChange(inputId, tags) {
// Update state.tags to look like:
// {input1: [1, 2, 3], input2: [4, 5, 6]}
let tagStateUpdateObject = {};
tagStateUpdateObject[inputId] = tags;
const newTagsState = Object.assign({}, this.state.tags, tagStateUpdateObject );
this.setState({
...this.state,
'tags': newTagsState
});
}
// and then render multiple inputs...
// While passing some props:
// 1. `handleChange` function
// 2. A unique `inputId` value
// 3. The contents of `this.state.tags`
} class FormInput extends React.Component {
constructor(props) {
super(props);
this.handleTagChange = this.handleTagChange.bind(this);
}
handleTagChange(tags) {
// This just sends the tags which you've input to the form's handleChange function
// but it must also send the inputId for this specific input.
this.props.handleChange(this.props.inputId, tags);
}
render() {
const inputvalue = this.props.tags[imageId] || [];
return <TagsInput value={inputValue} onChange={this.handleTagChange} />
}
} Hope this helps someone out there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to handle many tagsinput in a form or in a same component. It seems, it isn't supported
The text was updated successfully, but these errors were encountered: