This is a migrated thread and some comments may be shown as answers.

Pushing enter in edit modals brings up another modal

2 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 2
Luke asked on 13 Jun 2013, 11:22 PM
I have an editable RadGrid within a RadAjaxPanel that utilizes modal popups and form templates for editing.

When users try to insert a row and push enter, a second modal will come up for editing a row: Screenshot

We don't want to support users pressing enter to submit the modal anyway (they should just click the save button), so I'm trying to prevent the postback being caused by the enter key being pressed using javascript:

<ClientSettings AllowKeyboardNavigation="False">
     <ClientEvents OnKeyPress="BlockEnterKey"  />     
     <KeyboardNavigationSettings AllowSubmitOnEnter="false" />
</ClientSettings>

<script type="text/javascript">
  function BlockEnterKey(sender, e) {
    if (e.get_keyCode() == 13) {
      alert('Blocking Enter KeyPress');
      e.set_cancel(true);
      e.cancelBubble = true;
      return false;
    }
  }
</script>

Unfortunately this seems to have absolutely no effect (other than that alert I put in there to make sure it's running).

Any idea as to why I'm unable to block this keypress event?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 14 Jun 2013, 05:25 AM
Hi,

Please try the following code.Hope this helps you.

ASPX:
<ClientSettings  AllowKeyboardNavigation="true"  >
  <ClientEvents OnKeyPress="OnKeyPress"  />
</ClientSettings>

JS:
function OnKeyPress(sender, eventArgs)
 {     
    if (eventArgs.get_domEvent().rawEvent.keyCode == 13)
  {
     alert("Cancelling event");
     eventArgs.get_domEvent().preventDefault()
     eventArgs.get_domEvent().stopPropagation()
  }
}


Thanks,
Princy
0
Luke
Top achievements
Rank 2
answered on 14 Jun 2013, 04:24 PM

It looks like that works regardless of whether AllowKeyboardNavigation is set to true or false (which is important in my case). 

Thank you very much!

 

 

Tags
Grid
Asked by
Luke
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Luke
Top achievements
Rank 2
Share this question
or