Question

I'm using YUI 3 to let someone click "Select All" or "Select None" and then have the selectbox select all the items or unselect all of them, respectively. Here's my code:

// This selects all
    Y.on('click',function (e) {
            selectBoxNode.get("options").each(function () {
               this.removeAttribute('selected');
               this.setAttribute('selected','selected');
            });
        }, selectAllNode
    );

// This selects none
   Y.on('click',function (e) {
            selectBoxNode.get("options").each(function () {
               this.setAttribute('selected','false');
               this.removeAttribute('selected');
            });
            selectBoxNode.('selectedIndex',-1);
        }, selectNoneNode
    );

selectAllLink, selectNoneLink, and selectBoxNode are self-evident, properly returned Nodes. Update: selectAll works, I had to manually remove the 'selected' attribute for each and re-add it.

The selectNoneLink doesn't work: it unselects only the elements that weren't before selected... although DOM inspection shows that the selectedIndex attribute is indeed changed to -1, so maybe it needs a refresh?

Any help would be appreciated. If this happens in all frameworks, that would be nice to know as well.

Thanks!

Was it helpful?

Solution

This worked for me.

YUI().use('node', function(Y) {
   Y.get('#unsel').on('click', function(e) {
     Y.get('select').get('options').set('selected',false);
   });
   Y.get('#sel').on('click', function(e) {
     Y.get('select').get('options').set('selected', true );
   });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top