Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Add 'selected'-Attribute to Options #31

Closed
vanderb opened this issue Apr 16, 2013 · 0 comments
Closed

Add 'selected'-Attribute to Options #31

vanderb opened this issue Apr 16, 2013 · 0 comments

Comments

@vanderb
Copy link

vanderb commented Apr 16, 2013

var settings = {
    // ...
    selectedOpt: false // adds selected-attribute by text or value
}

Add function:

function addSelectedAttribute(value, text, container) {
    s = (settings.selectedOpt && (settings.selectedOpt == text || settings.selectedOpt == value)) ? " selected ": false;
    $('<option value="'+value+'" '+s+'>'+text+'</option>').appendTo(container);     
}

Edit function 'createOption':

//function to create options in the select menu
function createOption($item, $container, text){

    //if no text param is passed, use list item's text, otherwise use settings.groupPageText
    if(!text){
        addSelectedAttribute( $item.find('a:first').attr('href'), $.trim(getText($item)), $container );
    } else {
        addSelectedAttribute( $item.find('a:first').attr('href'), text, $container );
    }

}//createOption()

Only works for default options, but i think it's easy to making it available for opt-groups.

@vanderb vanderb closed this as completed Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant