简体   繁体   中英

submit input in text area using return without inserting a newline character

I have a binding for a textarea input in Shiny here . To submit the text entered press CTRL-return (CMD-return on Mac). I would prefer the text be submitted on pressing return (ie, without CTRL or CMD) but without creating a newline. Is this possible? Note: A textarea, rather than a textinput, is needed to provide enough space for input without some of the text being hidden.

EDIT: The binding works with CTRL-return (or CMD-return). On lines 18-22 I can use just event.keyCode == 13 and that submits the input but a newline character is also inserted in the textarea. It is that last part (ie, the newline) I would like to avoid.

You should prevent default behavior, which is inserting a new line, before calling your function.

if (event.keyCode == 13 && (event.metaKey || event.ctrlKey)) {
    event.preventDefault();
    ...
}

Your if statements at lines 28 and 30 need curly braces around the conditional parts.

Not sure, but this might be causing some issues...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM