Skip to content

Instantly share code, notes, and snippets.

@felipeands
Last active February 13, 2019 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save felipeands/b0285df812fcf63f2199acc21970bc27 to your computer and use it in GitHub Desktop.
Save felipeands/b0285df812fcf63f2199acc21970bc27 to your computer and use it in GitHub Desktop.
class Options extends React.Component {
constructor(props) {
super(props);
}
updateAlternative(e, key) {
this.props.questions[key].text = e.target.value;
}
dragulaDecorator(componentBackingInstance) {
if (componentBackingInstance) {
let dragEl = reactDragula([componentBackingInstance]);
dragEl.on('drop', (el, target, source, sibling) => {
console.log('source', source);
this.reorderItems(source);
});
}
}
reorderItems(source) {
console.log('reorder');
}
render() {
return(
<div className="container" ref={(e) => this.dragulaDecorator(e)}>
{this.props.questions.map((question, key) =>
<div key={question.id} className="option">
<hr />
<div className="form-group row">
<label className="col-sm-3 col-form-label">Opção</label>
<div className="col-sm-9">
<input type="text" name="question[]" className="form-control" defaultValue={question.text} onChange={(e) => this.updateAlternative(e, key)} />
<input type="hidden" name="question_order[]" defaultValue={question.order} />
</div>
</div>
<GoToChatbotMessage question={question} messages={this.props.messages} />
</div>
)}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment