react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Creatable: onNewOptionClick doesn't fire, doesn't seem to be present

Open benterprise opened this issue 10 years ago • 9 comments

newOptionCreator fires every keystroke but I can't find the onNewOptionClick referenced in the docs

benterprise avatar Nov 30 '16 16:11 benterprise

The NPM package doesn't seem to have this function

benterprise avatar Nov 30 '16 16:11 benterprise

There should be a way to hook into the creation process before the option is added to the select, I'd rather run the new option up through the store and down into the component than add it directly into the component

benterprise avatar Dec 01 '16 19:12 benterprise

I've got the same problem. @drsloth This functionality was pulled in https://github.com/JedWatson/react-select/pull/1364, you can download the master branch and compile it.

kamil-7 avatar Dec 08 '16 18:12 kamil-7

I'm using master, but the onNewOptionClick does not fire for me...am I missing something? I'm trying to trigger a modal when a user is trying to create a new option.

eamonpenland avatar Dec 23 '16 15:12 eamonpenland

No it's not totally implemented yet. The hook is present here: https://github.com/JedWatson/react-select/blob/master/src/Creatable.js#L41

but not here: https://github.com/JedWatson/react-select/blob/master/dist/react-select.js#L306

or here: https://github.com/JedWatson/react-select/blob/master/lib/Creatable.js#L51

On Fri, Dec 23, 2016 at 9:50 AM, Eamon Penland [email protected] wrote:

I'm using master, but the onNewOptionClick does not fire for me...am I missing something?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JedWatson/react-select/issues/1398#issuecomment-269008492, or mute the thread https://github.com/notifications/unsubscribe-auth/ALhvt8k82GS7as4eU6U5bQJudSwTkkdRks5rK-2-gaJpZM4LAXYc .

benterprise avatar Dec 23 '16 17:12 benterprise

Even I am facing this issue. Not able to fire newOptionCreator

hegdeas avatar Jan 23 '17 14:01 hegdeas

i've been doing a somewhat janky workaround

assuming you have simpleValue={true}, so your results are passed as a comma-delimited string:

 const _onChange = (newTags) => {
    const { currentTags } = props // tags that were already applied
    const newTagsArray = newTags.split(',')
    // find which value is new
    const [alteredValue] = newTagsArray.filter(tag => !currentTags.includes(tag))

    // fetch whatever array we're keeping our options in
    // turn it into an array of strings
    const allTagLabels = props.tagOptions.map(t => t.label)

    if (allTagLabels.includes(alteredValue)) {
      console.log(`${alteredValue} already existed`)
    } else {
      console.log(`${alteredValue} was created`)
    }
  }

then just pass this as your onChange

 <Select.Creatable
        simpleValue
        onChange={_onChange}
        ...props
        />

brandonmp avatar Jan 27 '17 22:01 brandonmp

@hegdeas It seem to work for me!!

monish001 avatar Feb 01 '17 06:02 monish001

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.

bladey avatar May 27 '20 06:05 bladey