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}"/>
6 Answers, 1 is accepted
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
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 >>
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
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;
}
Thanks you very about your help, it works wonderfully, :)
Hope you have a nice day.
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.
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;
}