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

TextBox with AcceptsReturn=true

7 Answers 448 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Roar
Top achievements
Rank 1
Roar asked on 29 Aug 2014, 11:41 AM
Hi,
I have a DataForm with an EditTemplate where I have a multiline TextBox for editing text. I need to be able to insert new lines by pressing the Return Key. But when I do that, the Dataform gets Comitted. How can I prevent the DataForm's Commit Command to fire when users press the Return key inside the TextBox?

7 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 01 Sep 2014, 10:31 AM
Hello,

RadDataForm has built-in keyboard navigation that executes the CommitEdit command, when "Enter" is pressed. You can override its default behavior, by using a custom command provider. You can check the Keyboard Support help article that sheds some more light on the matter. For your convenience, I have prepared a sample project which demonstrates the approach.

I hope it helps.

Regards,
Yoan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Roar
Top achievements
Rank 1
answered on 12 Sep 2014, 10:56 AM
Thanks, I got this working now.

Regards,
Roar Bjørndal-Rasmussen
0
Johannes
Top achievements
Rank 1
answered on 04 Feb 2015, 11:02 AM
I also need parts of this in my RadDataForms so first thank you very much for the example.

I try to make some additions because what I really want is that "Enter" and "Return" do not execute the same actions. If user hits "Return" DataForm should't do anything (except insert a new line in a multiline TextBox). But if user hits "Enter" I want the RadDataForm to execute commit no matter if Focus is in a multiline TextBox or a Combobox or any other DataFormField. Is this possible?

Note: It seems that when pressing "Enter" OR "Return" args.Key is always of value "Return" which makes it impossible to differ them. Any suggestions?
0
Ivan Ivanov
Telerik team
answered on 09 Feb 2015, 10:12 AM
Hello,

I believe that the difference between them is not distinguishable by the .Net framework. Both of the entries in the System.Windows.Input.Key enumeration have one and the same actual value.

/// <summary>The Return key. </summary>
        Return = 6,
        /// <summary>The Enter key. </summary>
        Enter = 6,


Regards,
Ivan Ivanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Johannes
Top achievements
Rank 1
answered on 11 Feb 2015, 10:54 AM
Hello Ivan,

You'e right. I read some more documentation and today "Return" should be seen as the same key as "Enter". I've changed my Commit key to Ctrl + Enter/Return and that's fine. Thanks for your help.
0
Gregg
Top achievements
Rank 1
answered on 18 Mar 2015, 11:57 PM
Hi Yoan,

Does your sample project solve the OP's problem? That is, does it insert a new line in the TextBox, rather than commit the DataForm, when Return/Enter key is pressed? When I apply your sample to my project, I notice that the position of the cursor in the TextBox is simply moved to the end of the text when the Return/Enter key is pressed. Nothing else happens, i.e. no new line. That behavior seems to be what you have coded in your sample:

TB.SelectionStart = TB.Text.Length;
TB.Focus();


I expected your sample to insert a new line instead. Am I missing something? How to achieve a new line in TextBox when Return/Enter key is pressed?

Thank you.
0
Yoan
Telerik team
answered on 23 Mar 2015, 08:45 AM
Hello Gregg,

The reason for this behavior is that I had set a fixed Height for the Textbox. If you remove that setting you will be able to insert a new line on pressing the Enter key. You can check this screencast for a reference. If you need further assistance on this, do not hesitate to contact me again.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataForm
Asked by
Roar
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Roar
Top achievements
Rank 1
Johannes
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Gregg
Top achievements
Rank 1
Share this question
or