Skip to content
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

how to get the new value in the callback handler? #61

Closed
smancang opened this issue Dec 30, 2016 · 8 comments
Closed

how to get the new value in the callback handler? #61

smancang opened this issue Dec 30, 2016 · 8 comments

Comments

@smancang
Copy link

smancang commented Dec 30, 2016

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.

@sznowicki
Copy link

It's e.target.val;

@hakunin
Copy link

hakunin commented Feb 10, 2017

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.

@siddhanttambe
Copy link

onChange callback is not firing in case of any text change in the select2 input box.
Is there another callback for this?

@sznowicki
Copy link

@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.

@siddhanttambe
Copy link

That is exactly what I was trying to avoid, @sznowicki .
Thanks all the same!

@sznowicki
Copy link

@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.

@rkit
Copy link
Owner

rkit commented Mar 6, 2017

Please, try this way:

<Select2 
  ref={(e) => { this.tags = e; }}
  onChange={() => {
    console.log(this.tag.el.val());
  }}
  // …
/>

@Dumbear
Copy link

Dumbear commented Jun 14, 2017

@rkit Should be this.tag = e instead of this.tags = e. And it works, thanks.

@rkit rkit closed this as completed Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants