Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mooselecta: Update a select dynamically

In our current project we have to maintain other guys codebase based on mootools. We make heavy use of this plugin https://github.com/DimitarChristoff/mooSelecta to style our select tags. Basically this plugin programatically creates a styled div representation of an ordinary select and moves the select-tag out of the viewport.

I have the need to populate an select tag based on an ajax call. This works fine for the select itself, but the styled div (created by mooselecta) is not updated - it keeps showing the old values.

Is there any chance to update this div using plain javascript?

Thanks in advance!

like image 588
vreen Avatar asked May 26 '26 07:05

vreen


1 Answers

this is what I consider 'abandonware' - though I am the author of mooSelecta - it was my first mootools class released.

Anyway, there were issues with dynamic updates and rebuilding of the lists - I just pushed a fix and tagged it as 1.6.1

See the example/index.html

eg code.

    document.getElement('button').addEvent('click', function(){
        var select = document.id('p_card_type3').empty(),
            c = 5;

        while(c--){
            select.adopt(new Element('option', {
                html: 'Dynamic Option ' + c,
                value: c
            }));
        }

        // reinitialize the plugin
        dynamicInstances.replaceSelect(select);
   });

keep in mind you'd have to update the plugin itself.

like image 93
Dimitar Christoff Avatar answered May 30 '26 04:05

Dimitar Christoff