javascript - Detecting Enter pressed in AUI Dialog -
i want detect if enter used in html textfield load dialog.
if enter pressed want simulate click on save
-button.
i tried many things, pushing code around:
$(document).keypress(function(e) { if (e.keycode == $.ui.keycode.enter) { $("#resulttextarea").val("enter gedrueckt"); $(this).find("button:savebtn").trigger("click"); } });
below aui-dialog (in tried above code)
aui().use('aui-dialog', 'liferay-portlet-url', function(a) { var dialog = new a.dialog({ title: 'new title', centered: true, modal: true, width: 500, height: 200, bodycontent:aui().one('#addtestdialog'), buttons: [ { label : "save" , id : "savebtn" , handler : function(){ savestuff(); this.close(); } } ], open: function() { $(document).keypress(function(e) { if (e.keycode == $.ui.keycode.enter) { $("#resulttextarea").val("enter gedrueckt"); $(this).find("button:savebtn").trigger("click"); } }); } }).render(); });
and html part defines body of dialog:
<div style="display:none;"> <div id="addtestdialog"> <portlet:actionurl name="addnote" var="addnoteurl" /> <br> <table style="width:100%;"> <tr> <td>name:</td> <td><input id="textinput" style="width:98%;height:20px;"></input></td> </tr> </table> </div> </div>
i checked api of alloyui , found this: http://deploy.alloyui.com/api/classes/dialog.html
under attributes: there no open used in every tutorial/code found. therefore cannot work (at least think so). tested initialize wont work either.
thank help/hints.
you can use jquery achieve task
i.e
$("#savebtn").keypress(function(event){ var keycode = (event.keycode ? event.keycode : event.which); if (keycode == '13') { // want } });
hth
Comments
Post a Comment