views:

688

answers:

1

Hi,

I am using openjs.com's shortcut handling (1) to disable the enter key in my html forms. However, inside of textareas in those forms I want enter key to emit the normal CR-LF pair (because that's what users expect).

At the moment assuming I have a form/input structure as follows:

<form id="f1">
 <fieldset>
  <input>
  <textarea id="f2"> ...

The following scripts are run:

shortcut.add('Return',  function () { /*empty*/   },
 { 'type':'keydown', 'disable_in_input':false,'propagate':true,  
   'target':document.getElementById('f1')});"

This effectively disables the enter key.

I have tried using the following code to re-enable it for the textarea:

shortcut.add(\"Enter\", function() { }, {'type':'keydown','propagate':false,
'disable_in_input':false, 'target':document.getElementById('f2') } );

But that does not work. What is the order of propagation of this event? Should it bubble up from the textarea or bubble down from the form element?

+2  A: 

It doesn't look like this library was really meant to be used this way. I would hazard a guess that adding any shortcut disables the browser's handling of it entirely, no matter what you do afterwards.

What are you actually trying to accomplish? If you just want to prevent the form from being submitted, you could add a submit event listener for the whole form that calls event.preventDefault().

Eevee