diff --git a/jquery.jeditable.js b/jquery.jeditable.js index eb8a911..e8d3b2a 100644 --- a/jquery.jeditable.js +++ b/jquery.jeditable.js @@ -48,6 +48,7 @@ * @param String options[select] true or false, when true text is highlighted ?? * @param String options[placeholder] Placeholder text or html to insert when element is empty. ** * @param String options[onblur] 'cancel', 'submit', 'ignore' or function ?? + * @param String options[ontab] 'submit', or 'escape', block default browser tab action and take our own action * * @param Function options[onsubmit] function(settings, original) { ... } called before submit * @param Function options[onreset] function(settings, original) { ... } called before reset @@ -261,6 +262,15 @@ e.preventDefault(); reset.apply(form, [settings, self]); } + if (e.keyCode === 9) { + if (settings.ontab === "escape") { + e.preventDefault(); + reset.apply(form, [settings, self]); + } else if (settings.ontab === "submit"){ + e.preventDefault(); + form.submit(); + } + } }); /* Discard, submit or nothing with changes when clicking outside. */ @@ -492,29 +502,44 @@ /* Otherwise assume it is a hash already. */ var json = data; } - for (var key in json) { - if (!json.hasOwnProperty(key)) { - continue; + for (var item in json) { + var option_key; + var option_value; + if ($.isArray(json)) { + option_key = json[item][0]; + option_value = json[item][1]; + } else { + if (!json.hasOwnProperty(item)) { + continue; + } + option_key = item; + option_value = json[item]; } - if ('selected' == key) { + + if ('selected' == option_key) { continue; - } - var option = $('