-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Input field of mutiselect creatable field is not cleared after new tag cration #1663
Comments
@Falenos Same here. Here's a gnarly workaround for you - this is MobX code, so yours may be a bit different. Grab a ref to the creatable component like so <Creatable
disabled={saving || frozen}
placeholder="Tag this section"
ref={el => this.creatableEl = el} // <-------- here
onNewOptionClick={obj => store.addNewTag(obj, this.creatableEl)}
onChange={store.setTags}
value={store.rawTags}
multi={true}
options={sectionTagStore.allTags} /> and then @action addNewTag = (obj, creatableEl) => {
this.tags.push(sectionTagStore.createTag(obj));
creatableEl.select.setState({inputValue: ''}); // <------- clears the input text
} So the ref to the Creatable component has a select property on it which (I assume) is the underlying multi component. Set its state's |
@arackaf thanks a lot for the tip. It got me really close but still not there, it really is a bit gnarly though. I am relatively new in react and from your suggestion I checked out refs for the first time... What happened is that my component that renders the "Select" is stateless and is not declared as a Class maybe that's why it's not working, but I need to research further. The creatableEl.select.setState(); gives me nothing. There is a State object in Select so creatableEl.select.State exists but the .setState() method is not available. The code is below, if you have any suggestions...
|
@Falenos not sure. You should be able to add the ref to the Creatable in your SFC, and then whatever event handler that needs to use it would be called from within the closure, with access to the ref. At this point though I'd just make your component a class; I don't see any real value to making an SFC bloated like that. imo SFCs fit better with simpler components that aren't doing very much. |
@arackaf will do and get back on you, thanks |
Just ran into this issue, the suggestion worked perfectly. Thanks for that, @arackaf. Would be neat if the input was cleared automatically by default, but not sure what other kinds of issues that might create. |
@arackaf I ran into this, too. I'm relatively new to the library; is this low-hanging fruit for contributors, or are there a bunch of edgy cases that would trip me up if I tried? I'm also using |
@smelted-code there are currently 133 open pull requests. I'd advise you NOT to PR this unless the owner of this project tells you he'll accept it. I mean, if you want to try to fix it just to see if you can, and won't mind if the PR is ignored, then go for it. But don't go trying to fix it unless you're ok with the PR lingering for a bit. No offense intended to the project's owner. We all have limited time during the week - I just don't want a new contributor to get frustrated :) |
@arackaf I made progress on the issue with a different approach. Because we needed some functionality that wasn't there either way, like being able to delete the Eitherway from my current knowledge of how thing work this is what I saw. There is a method in Select.js called If you decide to make your own fork or edit the core somehow like we did, my first approach was to create a new method in
There are also 2 boolean props that might become handy if you pass them to Select from you app. So, my current approach is calling the existing Select My general advice would be to check the methods that |
@Falenos - thanks a ton for the info. This project is great - look forward to seeing what's ahead for it. |
The following worked for me :
Notice the ref attribute is a function that stores the component into this.selector variable
|
@josefano thanks for that, it almost entirely worked for me. I found that in my |
I am closing this :) i think the discussion is obsolete at this point |
For reasons unknown the input field of a mutiselect creatable field is not cleared after new tag creation.
I click on create newTag, newTag is displayed on the field and next to it the input stays as is
Is there a method I can call when a new tag is stored to clear the input?
I know its supposed to work by default, but in my case it is not happening.
The text was updated successfully, but these errors were encountered: