Closed smancang closed 6 years ago
It's e.target.val;
Proper way of getting the value is $(e.target).select2().val()
IMO, as that will give you whatever you passed into the element / or was selected by UI instead of the string representation from DOM.
onChange callback is not firing in case of any text change in the select2 input box. Is there another callback for this?
@siddhanttambe sadly, as far as I remember you need to bind to jquery event on real element. Not sure if "ref" works here, I guess it's not and you need to use ReactDOM.getdomnode.
That is exactly what I was trying to avoid, @sznowicki . Thanks all the same!
@siddhanttambe "Leben is kein Ponyhof". We just used it as it is since we consider it legacy anyway, but maybe you could fix this issue within this repo.
Please, try this way:
<Select2
ref={(e) => { this.tags = e; }}
onChange={() => {
console.log(this.tag.el.val());
}}
// …
/>
@rkit Should be this.tag = e
instead of this.tags = e
. And it works, thanks.
There is only one parameter in the callback function, it is like an event object.But how to get the new value when changing selection.The parameter has a data property, but its value is always null.Should it be getten by the '.target.value' ? what if I set it multiple?what's more, when I select one option the dropdown doesn't fold automatically.