Mulitline textbox AcceptsReturn not working.

7 posts, 0 answers
  1. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 28 Jun 2013 Link to this post

    I have a mulitline textbox in my raddataform's edit template, with AcceptsReturn="True".
    When the user hits enter in this feild, instead of getting a new line, the dataform submits and ends the edit. 

    This thread seems to indicate this shouldn't be an issue:
     http://www.telerik.com/community/forums/silverlight/data-form/multiline-dataformdatafield.aspx 

    How can I get this to work correctly?
    I am using the lastest release 2013 Q2.
    Thanks.

    <DataTemplate x:Key="Note_EditTemplate">

    <StackPanel>

    <telerik:DataFormDataField DataMemberBinding="{Binding Note, Mode=TwoWay}" Label="Note :" >

    <TextBox Text="{Binding Note, Mode=TwoWay}" TextWrapping="Wrap" Height="100" Width="300" AcceptsReturn="True" MaxLength="1024"/>

    </telerik:DataFormDataField>

    <telerik:DataFormDataField DataMemberBinding="{Binding Created, StringFormat=d}" Label="Created :" IsReadOnly="True" />

    <telerik:DataFormDataField DataMemberBinding="{Binding Modified, StringFormat=d}" Label="Modified :" IsReadOnly="True" />

    </StackPanel>

    </DataTemplate>

     

    <telerik:RadDataForm Grid.Column="1" x:Name="data_UnitNotes" ItemsSource="{Binding UnitNotes.View}" VerticalAlignment="Top"

    CommandButtonsVisibility="Add,Edit,Delete,Cancel,Commit" AutoGenerateFields="False" Margin="5,0,0,0"

    AddedNewItem="data_UnitNotes_AddedNewItem_1" DeletedItem="data_UnitNotes_DeletedItem_1"

    BeginningEdit="data_UnitNotes_BeginningEdit_1" EditEnded="data_UnitNotes_EditEnded_1"

    EditTemplate="{StaticResource Note_EditTemplate}"

    ReadOnlyTemplate="{StaticResource Note_ReadTemplate}"

     NewItemTemplate="{StaticResource Note_EditTemplate}"/>

     

     

     

  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 01 Jul 2013 Link to this post

    Hello,

     We have introduced 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. Here is an article that sheds some more light on the matter.

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Thnghi
    Thnghi avatar
    9 posts
    Member since:
    Feb 2013

    Posted 27 Aug 2013 Link to this post

    Hi all,

    I have the same issue,
    I have a form with Description field:

     <controls:DataFormDataField.ContentTemplate>
                                                <DataTemplate>
                                                    <TextBox TextWrapping="Wrap" Text="{Binding Description, Mode=TwoWay}" VerticalScrollBarVisibility="Auto"  AcceptsReturn="True" MaxHeight="100" MinHeight="40"
                                                             KeyDown="UIElement_OnKeyDown"/>
                                                </DataTemplate>
                 </controls:DataFormDataField.ContentTemplate>


    I try to use CustomKeyboardCommandProvider:

     public override List<DelegateCommandWrapper> ProvideCommandsForKey(KeyEventArgs args)
            {
                List<DelegateCommandWrapper> actionsToExecute = base.ProvideCommandsForKey(args);
                if (args.Key == Key.Enter)
                {
                    actionsToExecute.Clear();

                }

                return actionsToExecute;
            }


    but it does not close form only, and the Description field does not add new line as expected.

    Has any one fixed this issue, please help me

    Thanks you very much

  5. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 27 Aug 2013 Link to this post

    I used the custom command provider to determine if the original source is a textbox that accepts returns. Hope this helps!

            public override List<DelegateCommandWrapper> ProvideCommandsForKey(KeyEventArgs args)
            {
                List<DelegateCommandWrapper> actionsToExecute = base.ProvideCommandsForKey(args);

                if (args.Key == Key.Enter)
                {
                  
                        if (args.OriginalSource is TextBox && (args.OriginalSource as TextBox).AcceptsReturn)
                        {
                            TextBox TB = args.OriginalSource as TextBox;

                            actionsToExecute.Clear();

                            StringBuilder SB = new StringBuilder(TB.Text);
                            TB.Text = SB.AppendLine().ToString(); //add new line

                            TB.SelectionStart = TB.Text.Length; //move cursor to end
                            TB.Focus();
                        }
                        else
                        {
                            actionsToExecute.Clear();
                            actionsToExecute.Add(new DataFormDelegateCommandWrapper(RadDataFormCommands.CommitEdit, this.DataForm));
                        }
                  
                }
             
                ...
               
                return actionsToExecute;
            }

  6. Thnghi
    Thnghi avatar
    9 posts
    Member since:
    Feb 2013

    Posted 27 Aug 2013 Link to this post

    Hi Jen,

    Thanks you very about your help, it works wonderfully, :)

    Hope you have a nice day.
  7. Rami Abughazaleh
    Rami Abughazaleh avatar
    27 posts
    Member since:
    Feb 2010

    Posted 01 Apr 2015 Link to this post

    Thank you jen for the sample code.

    The only issue I found is that pressing the enter key in-between text within the textbox does not add a new line at the cursor position, but will always append a new line at the end of all characters in the textbox which is unexpected.
  8. Rami Abughazaleh
    Rami Abughazaleh avatar
    27 posts
    Member since:
    Feb 2010

    Posted 01 Apr 2015 in reply to Rami Abughazaleh Link to this post

    I've updated jen's code to resolve the issue as follows:

            public override List<DelegateCommandWrapper> ProvideCommandsForKey(KeyEventArgs args)
            {
                List<DelegateCommandWrapper> actionsToExecute = base.ProvideCommandsForKey(args);

                if (args.Key == Key.Enter)
                {
                    if (args.OriginalSource is TextBox && (args.OriginalSource as TextBox).AcceptsReturn)
                    {
                        TextBox textBox = args.OriginalSource as TextBox;

                        actionsToExecute.Clear();

                        StringBuilder stringBuilder = new StringBuilder(textBox.Text);
                        stringBuilder.Insert(textBox.SelectionStart, Environment.NewLine); // add new line
                        textBox.Text = stringBuilder.ToString();

                        textBox.SelectionStart += 3; // move cursor to new line
                        textBox.Focus();
                    }
                    else
                    {
                        actionsToExecute.Clear();
                        actionsToExecute.Add(new DataFormDelegateCommandWrapper(RadDataFormCommands.CommitEdit, this.DataForm));
                    }
                }

                return actionsToExecute;
            }
Back to Top
DevCraft banner