javascript - Jquery contextMenu plugin fails to accept default selection -


utilizing example here

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

refuses have default selection of drop down menu two , instead leaves one . using jquery 1.8, there known issue above code on version or there workaround can put in place? issue persists on demo page.

environment: jquery 1.8 firefox 19.0 

working fiddle

i checked plugin, think never worked selected value of select, use current value run time.

this because setinputvalues function set selected property if undefined in data object. have fixed code setting property if data object not undefined.

see:

// import values <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 pastebin of fixed code: http://pastebin.com/mg3j7ifb

if works weel i'll fork fix.

edit

added support radio , checkbox too:

// import values <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/


Comments