olton / Metro-UI-CSS

Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
http://metroui.org.ua/
MIT License
7.03k stars 1.96k forks source link

Change Selected Items in a MultiSelect at RunTimes #1421

Closed 3asit closed 5 years ago

3asit commented 5 years ago

if "multiselect" attribute is added to the select. i get again select is undefined error So i am unable to set the selected items. And i include Metro 4 into page, before the jquery function

Originally posted by @3asit in https://github.com/olton/Metro-UI-CSS/issues/1317#issuecomment-536780368

3asit commented 5 years ago

If you put a multiselect, inside a modal, and you try to set selected item at runtime it doesn't work. the function $(el).data('select') retrive nothing.

I tried with different version of metroui, and changing the order between jquery and metroui js.

i find that thre is a conflict betweent jquery and metroui, and if i call m4q(el).data('select') this work properly.

olton commented 5 years ago

Hi, Thanks for your time. After release 4.3.x, some aspects were changed (this is due to the interaction of Metro 4 and jquery). Now, if you use jquery, you must use a method Metro.getPlugin(el, plugin_name) This is a changed example code for change select options at runtime.

        function updateSelect(v){
            m4q.get("data/"+v).then(function(response){
                var select = Metro.getPlugin($("#select1"), "select");
                select.data(v.indexOf("json") === -1 ? response : JSON.parse(response));
            });
        }

Sorry, I can’t give a more detailed answer, I’m in the hospital, some heart problems.

3asit commented 5 years ago

Thanks. First i hope you fixed most important bug about your heart!! and stay well.

Anyway i have tried from Metro version 4.2.49 to the last dev version, using Jquery version 3.4.1 or 3.3.1. Only if i exclude Jquery from the project, selected item at runtime works well

I completely fix the problem, using m4q instead of $ in the call.

Best Regards.