Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Material Select Editable - Add new item doesn't fire on change() or any callback I can find :(

seonr premium asked 5 years ago


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


cdenby pro answered 3 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 3 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


cdenby pro answered 3 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 3 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.


Sebastian Kaczmarek staff 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.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Premium
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.8.11
  • Device: Mac
  • Browser: safari
  • OS: macOS 10.14
  • Provided sample code: Yes
  • Provided link: No