Skip to content

Patch to allow suppressing of open event #208

@michaelcaplan

Description

@michaelcaplan

Hi there,

I found myself needing a way to suppress the opening selectmenu (do optionally allow the opening of a full screen dialog window with advanced tools for navigating the select options). I did this by adding a beforeOpen event that can be used to cancel the open event.

The patch looks like this:

    open: function(event) {
        var self = this, o = this.options;
        if ( self.newelement.attr("aria-disabled") != 'true' ) {
            self._closeOthers(event);

            if (self._trigger("beforeOpen", event, self._uiHash()) === false) {
                return;
            }

            self.newelement.addClass('ui-state-active');

            self.listWrap.appendTo( o.appendTo );
            self.list.attr('aria-hidden', false);           
            self.listWrap.addClass( self.widgetBaseClass + '-open' );

            var selected = this._selectedOptionLi();
            if ( o.style == "dropdown" ) {
                self.newelement.removeClass('ui-corner-all').addClass('ui-corner-top');
            } else {                
                // center overflow and avoid flickering
                this.list
                    .css("left", -5000)
                    .scrollTop( this.list.scrollTop() + selected.position().top - this.list.outerHeight()/2 + selected.outerHeight()/2 )
                    .css("left","auto");
            }

            self._refreshPosition();    

            var link = selected.find("a");
            if (link.length) link[0].focus();       

            self.isOpen = true;
            self._trigger("open", event, self._uiHash());
        }
    },

I'm including it here for consideration.

Thanks,

Mike

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions