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

Skip keyboard presses for some predefined commands

6 Answers 45 Views
Editor
This is a migrated thread and some comments may be shown as answers.
QualiWareUA
Top achievements
Rank 1
QualiWareUA asked on 19 Aug 2008, 12:55 PM
Hi guys,

I'm struggling with little problem now - how to prevent Enter hitting. For example such piece of code
function onEditorClientLoad(editor, args) 
    editor.attachEventHandler("onkeydown"
        function(e) 
        { 
            if (document.all) 
            {   
                e.cancelBubble = true;   
                e.returnValue = false;   
                return false;   
            }   
            else   
            {   
                e.preventDefault();   
                return false;   
            }   
        } 
    ); 
helps us to discard any symbol key hitting, but not Enter, or Ctrl-A, and so on.
But in my case I really want to cancel Enter, if it is done inside link, and thus prevent creating two separate links.
Any help would be appreciated. Thanks in advance.

Sergey.

6 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 20 Aug 2008, 11:05 AM
Hi Sergey,

You can achieve the desried behavior using the following code:
<script type="text/javascript">  
    function OnClientLoad(editor, args)  
    {  
        editor.attachEventHandler("onkeydown"function(e)      
        {                      
            var key = e.keyCode;  
            var shift = e.shiftKey;  
            if (shift && key == "13")  
            {  
              $telerik.cancelRawEvent(e);  
              return false;  
            }  
            if (key == "13")  
            {  
              $telerik.cancelRawEvent(e);  
              return false;  
            }  
        });     
    }          
</script>  
<telerik:RadEditor Id="RadEditor1" Runat="server"   
      OnClientLoad="OnClientLoad">  
</telerik:RadEditor> 


Regards,
George
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
QualiWareUA
Top achievements
Rank 1
answered on 21 Aug 2008, 11:02 AM
Sorry, I didn't mentioned this at first time. Setting RadEditor property
NewLineBr="false" 
makes suggested by George solution unworkable in FireFox.
In IE all works fine.
0
George
Telerik team
answered on 25 Aug 2008, 11:15 AM
Hi Sergey,

The default behavior of the Enter command in Mozilla (Gecko) editors is to insert a <br> tag. In order to provide support for paragraph insertion under Firefox we made a custom implementation (NewLineBr="false") which has its limitations because of the different browser problems and behaviors. The observed behavior is a side effect of our code which handles the enter key event. However, note that there is no need of setting the NewLineBr property, because when the enter key is prevented no new lines will be inserted.
 
I hope this helps.

Kind regards,
George
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
QualiWareUA
Top achievements
Rank 1
answered on 26 Aug 2008, 08:56 AM
Hi George,

We have to set NewLineBr to false, because such behaviour is being expected by our users.
I posted here simplified project. In reality it's checked if cursor is in link scope and in this case Enter should be prevented.
It'll be really excellent if we could rewrite your Enter processor in some way. I mean using your implementation as base in every case, except some special situations as mentioned above.

Best regards,
Sergey.
0
George
Telerik team
answered on 26 Aug 2008, 01:41 PM
Hi Sergey,

I prepared a sample code that demonstrates how to achieve the desired behavior. Please review it bellow:
<script type="text/javascript">     
    function OnClientLoad(editor, args)     
    {     
        //IE  
        editor.attachEventHandler("onkeydown"function(e)         
        {                         
            var key = e.keyCode;     
            var shift = e.shiftKey;     
            if (shift && key == "13")     
            {     
              $telerik.cancelRawEvent(e);     
              return false;     
            }     
            if (key == "13")     
            {     
              $telerik.cancelRawEvent(e);     
              return false;     
            }     
        });        
        //FF  
        editor.add_commandExecuting(function(sender,args)  
        {                   
            if (args.get_commandName() == "EnterParagraphMozilla")  
            {  
                args.set_cancel(true);  
            }  
        });  
    }             
</script>     
<telerik:RadEditor Id="RadEditor1" NewLineBr="false" Runat="server"      
      OnClientLoad="OnClientLoad">     
</telerik:RadEditor>   

I hope this helps.

Have a great day,
George
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
QualiWareUA
Top achievements
Rank 1
answered on 26 Aug 2008, 02:17 PM
Hi George,

Great thanks, now it is working as I wanted.

Best regards,
Sergey.
Tags
Editor
Asked by
QualiWareUA
Top achievements
Rank 1
Answers by
George
Telerik team
QualiWareUA
Top achievements
Rank 1
Share this question
or