I am using jquery rich text editor jwysiwyg , i am able to submit the content on pressing enter key, by adding line
if(event.keyCode == 13) {
jQuery('#submit_button_id').focus().click();
}
in function $(this.editorDoc).keyup(function (event)
Problem now is shift+ENTER key also submit the value , cursor is not going to new line.
Is there any way such that on pressing shift+ENTER goes to new line.
Thanks in advance.
I think you'll have to store whether shift is down in a variable. So in keydown you'll have (in pseudocode):
if(event.keyCode === KEYCODE_SHIFT) shiftDown = true;
and in keyup the opposite
if(event.keyCode === KEYCODE_SHIFT) shiftDown = false;
and then in keyup check:
if(event.keyCode === 13 && !shiftDown) {
...
EDIT
Actually, you can probably just use the event.shiftKey property:
if(!event.shiftKey && event.keyCode === 13) {
...
Related
function onkeydown(e) {
if (e.key === "enter")
e.preventDefault()
}
<ReactQuill onKeyDown={onkeydown}/>
Here iam unable to prevent the enter key.
What you are looking for is this.
function onkeydown(e) {
if (e.keyCode === 13)
e.preventDefault()
}
Since the keyCode of the Enter key event is 13
}
I am using GWT components for web page. In my page I used ten text boxes. I want to block "tab" key event for navigate one text box to another text box.
Expected Approach: If I pressed tab key it wont go to another text box.
You can do somthing like this.
window.onkeydown = function() {
if (event.keyCode == 9) {
event.preventDefault();
}
}
Use NativePreviewEventHandler and use the logic mentioned by Mayank Pandya, which is
if (event.keyCode == 9) {
event.preventDefault();
}
Check for the Tabkey keycode. I am not sure about it.
I am working on an ASP.net MVC 4.0 application with Jqgrid.
I am making all rows as editable with some columns being editable and some non editable.
The Problem here is , i dont want to use Save and ESC handlers.
I am saving row details on the blur event of one of the text boxes. and still i need to stay in EDIT Mode.
So, if the user mistakenly presses enter , the row is going out of edit mode.
How to disable these Esc and Save Handlers
Please help..
Updated:
I am not using either cell edit or inline editing or form editing.
I am converting all rows as editable on the loadComplete trigger of the Jqgrid
i have only one Column being editable. that is of type Textbox
So, on the blur event of it , i am saving that to database using an ajax post .
Every thing is working fine upto this.
Here, the grid needs to be in edit mode even after saving value to database.
But, when clciking on enter on that row, it is moving out of edit mode which violates my requirement
I need to stop row moving to View mode from edit mode when ESC or Enter Keys are pressed
I hope this is clear..if not i will mention more..
I Solved it in this way:
Dont know whether it is right way of doing this:
Oleg..i need your views on this:
if(cnt > 0) {
svr.id = rowid; $t.p.savedRow.push(svr);
$(ind).attr("editable","1");
$("td:eq("+focus+") input",ind).focus();
if(o.keys===true) {
$(ind).bind("keydown",function(e) {
if (e.keyCode === 27) {
// debugger
// $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
// if($t.p._inlinenav) {
// try {
// $($t).jqGrid('showAddEditButtons');
// }
// catch (eer1) {}
// }
return false;
}
if (e.keyCode === 13) {
// var ta = e.target;
// if(ta.tagName === 'TEXTAREA') { return true; }
// if( $($t).jqGrid("saveRow", rowid, o ) ) {
// if($t.p._inlinenav) {
// try {
// $($t).jqGrid('showAddEditButtons');
// } catch (eer2) {}
// }
// }
return false;
}
});
}
$($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
}
This is the code , i found in the Jqgrid.src.js
Since, i done need restoreRow and saveRow to be called when Enter key or ESC is pressed, i commented out the code .
I dont know if it is right way to do it. but, this worked indeed for my Scenario.
I'm writing a windows store app (HTML) that includes some simple rich-text editing. I can apply bold to the currently selected using a button which fires document.execCommand("bold",false,null);
However when I bind this to a keydown event like CTRL+B, nothing happens. Here's my keydown code.
document.addEventListener("keydown", catchShortCuts, false);
function catchShortCuts(e) {
if (e.ctrlKey) {
if (e.keyCode == 66) // b
document.execCommand('bold', true, null);
}
}
}
I know my keydown code works fine because if I replace the document.execCommand with another line of code it fires just fine when I press CTRL+B. It seems like execCommand has a problem with the keydown event?
Turns out that it works fine if you use keypress instead of keydown. Just in case anyone else has the same issue, that's a workaround. Still not sure why onkeydown doesn't work though.
Working code:
document.addEventListener("keypress", catchShortCuts, false);
function catchShortCuts(e) {
if (e.ctrlKey) {
if (e.keyCode == 66) // b
document.execCommand('bold', true, null);
}
}
}
I am trying to make my gridview control in ASP.Net do a multi sort based on if the user pressed Ctrl key when trying to sort by clicking on a column name. The problem is that when I am using Firefox, if I click on a column name with Ctrl key pressed, the browser tries to open "javascript:__doPostBack('ctl00$ContentPla..." link in a new tab. IE and Chrome both don't do this unless the link is a real link.
Is there a way I can prevent Firefox from opening the link in a new tab and still cause the page to postback normally?
Thanks.
You need to capture the event of the Ctrl key being pushed down, using document.onKeyDown.
In your event handler, check if 'Ctrl' (key code 17) was pressed, as follows:
function document_keyDown(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
if (KeyID == 17) {
ctrlDown = true;
}
}
Here, I'm setting a 'ctrlDown' variable to true.
For the onKeyUp event, you can do the exact opposite:
function document_keyUp(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
if (KeyID == 17) {
ctrlDown = false;
}
}
Then, in the click event of your column elements, you can check if Ctrl has been clicked or not:
function columnElement_click() {
if (ctrlDown != undefined && ctrlDown == true)
alert("Ctrl + Click Received");
return false;
}
Make sure your column click handler returns false. Otherwise, the browser will execute the code, but then navigate to the address in the link's 'href' attribute.
Hope this helps.
(See also: http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html)