Topic: Material Select Editable - Add new item doesn't fire on change() or any callback I can find :(
When adding a new item to the list using editable="true"
the item is added to the list, but onchange()
is not fired :(
How do I get a callback when a new item has been added and selected?
Thanks, Seon
Sebastian Kaczmarek staff pro premium answered 5 years ago
Currently, there's no support for that. You have to use custom code to attach a click
event to the i.select-add-option
element and then manually .trigger('change')
on the <select>
element.
cdenby pro answered 4 years ago
Is this the code you are suggesting?
$("i.select-add-option").click(function(){
$("i.select-add-option").closest("div.select-wrapper").find("select").first().trigger("change");
});
My biggest problem with this is that I load almost all of my content through Ajax and the post-load routines are fairly substantial. So every time I load through ajax, I have to add this.
It's not an ideal solution. I'm surprised this hasn't been resolved.
cdenby pro commented 4 years ago
Actually no - that doesn't work. The first time, it will work. But after the selection is made, it appears that the i.select-add-option is destroyed and rebuilt on the next dropdown open.
cdenby pro answered 4 years ago
I can't get this binding to work. I can bind the trigger("change") when the control is loaded, but every time a selection is made, the i.select-add-option is destroyed. I would need to have a onShown event available in order to rebind the action to the i.select-add-option that is generated by showing.
I can't find documentation of the equivalent of the Bootstrap onShown event: https://getbootstrap.com/docs/4.0/components/dropdowns/#events
If I could have that onShown event to leverage, I could rebind the i.select-add-option to the code above and make this control work.
Is it possible that the events for Material Select in MDB 4.19 are documented somewhere that I can't find?
Krzysztof Wilk staff commented 4 years ago
Hi!
The described functionality of the component is not included in our specification. At the moment, we do not plan to expand the capabilities of the component so as not to degrade its stability.
Best regards
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: Yes
- Technology: MDB jQuery
- MDB Version: 4.8.11
- Device: Mac
- Browser: safari
- OS: macOS 10.14
- Provided sample code: No
- Provided link: No