1

Utilizing the example here

 select: {
                name: "Select", 
                type: 'select', 
                options: {1: 'one', 2: 'two', 3: 'three'}, 
                selected: 2
            }

refuses to have the default selection of the drop down menu be two and instead leaves it as one . We are using jQuery 1.8, is there a known issue with the above code on this version or is there some workaround that can be put in place? The issue even persists on the demo page.

Environment:
jQuery 1.8
Firefox 19.0

working fiddle

1 Answer 1

3

I checked the plugin, I think it never worked with selected value of the select, but it use the current value only a run time.

This is because the setInputValues function set the selected property if is it undefined in the data object. I have fixed the code by setting the property only if the data object is not undefined.

See:

// import values into <input> commands
$.contextMenu.setInputValues = function(opt, data) {
    if (data === undefined) {
        data = {};
    }

    $.each(opt.inputs, function(key, item) {
        switch (item.type) {
            case 'text':
            case 'textarea':
                item.value = data[key] || "";
                break;

            case 'checkbox':
                item.selected = data[key] ? true : false;
                break;

            case 'radio':
                item.selected = (data[item.radio] || "") == item.value ? true : false;
                break;

            case 'select':
                if (data[key]!=undefined ){
                  item.selected = data[key] || "";
                }
                break;
        }
    });
};

Working fiddle: http://jsfiddle.net/vYnv3/1/

Here is a pastebin of the fixed code: http://pastebin.com/Mg3j7ifB

If works weel I'll fork the fix.

EDIT

Added support for radio and checkbox too:

// import values into <input> commands
$.contextMenu.setInputValues = function(opt, data) {
    if (data === undefined) {
        data = {};
    }

    $.each(opt.inputs, function(key, item) {
        switch (item.type) {
            case 'text':
            case 'textarea':
                item.value = data[key] || "";
                break;

            case 'checkbox':
                if (data[key]!=undefined ){
                    item.selected = data[key] ? true : false;
                }
                break;

            case 'radio':
                if (data[item.radio]!=undefined ){
                    item.selected = (data[item.radio] || "") == item.value ? true : false;
                }
                break;

            case 'select':
                if (data[key]!=undefined ){
                  item.selected = data[key] || "";
                }
                break;
        }
    });
};

New pastebin: http://pastebin.com/c8XFVMiD

Working fiddle: http://jsfiddle.net/vYnv3/2/

Sign up to request clarification or add additional context in comments.

1 Comment

That does fix the selected issue on the select box, however it does not resolve the checkbox (boolean fields)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.