select submit by enter

This commit is contained in:
vitalets 2012-12-06 15:30:19 +04:00
parent 663aeffd65
commit a8147f33af
3 changed files with 36 additions and 2 deletions

@ -4,6 +4,7 @@ X-editable changelog
Version 1.2.0 wip
----------------------------
[enh] 'select' submit by enter (vitalets)
[bug #37] fix incorrectly shown datepicker in jquery 1.7.1 + webkit (vitalets)
[enh] added url param 'jquery' to run tests in different versions of jquery, e.g. '&jquery=1.7.2' (vitalets)
[enh] 'enablefocus' option removed. More efficient to use 'save/hide' events to set focus to any element (vitalets)

@ -37,6 +37,13 @@ $(function(){
for(var i=0; i<this.sourceData.length; i++) {
this.$input.append($('<option>', {value: this.sourceData[i].value}).text(this.sourceData[i].text));
}
//enter submit
this.$input.on('keydown.editable', function (e) {
if (e.which === 13) {
$(this).closest('form').submit();
}
});
},
value2htmlFinal: function(value, element) {
@ -48,7 +55,7 @@ $(function(){
},
autosubmit: function() {
this.$input.on('change', function(){
this.$input.off('keydown.editable').on('change.editable', function(){
$(this).closest('form').submit();
});
}

@ -551,6 +551,32 @@ $(function () {
e.remove();
start();
}, timeout);
});
});
asyncTest("submit by enter", function () {
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php"></a>').appendTo(fx).editable({
pk: 1,
source: groups
}),
selected = 3;
e.click();
var p = tip(e);
p.find('select').val(selected);
event = jQuery.Event("keydown");
event.which = 13;
p.find('select').trigger(event);
setTimeout(function() {
ok(!p.is(':visible'), 'popover closed');
equal(e.data('editable').value, selected, 'new value saved')
equal(e.text(), groups[selected], 'text shown correctly')
e.remove();
start();
}, timeout);
})
});