I have dependent fields like this
If you're using refs
[docs], you can access the node via its refs
attribute in the componentDidMount
function and pass that to select2()
:
var Select = React.createClass({
handleChange: function () {
this.prop.onChange(
this.refs.myRef.value
);
},
componentDidMount: function () {
// Call select2 on your node
var self = this;
var node = this.refs.myRef; // or this.refs['myRef']
$(node)
.select2({...})
.on('change', function() {
// this ensures the change via select2 triggers
// the state change for your component
self.handleChange();
});
},
render: function () {
return (
);
}
});
I don't believe this is the "React way," but this may help if you don't want to use react-select
or some other tool.