Hi Syncfusion,
I'm trying to be able to focus off the RTE and then selecting an item from a sortable list and then inserting the selected text in the last cursor position.
I've tried multiple things, but I can't seem to get the RTE to save it's cursor position on e.g. the Blur event & then to be restored after an item from the list is selected (or a button is clicked).
I've tried using the rteObj.SaveSelectionAsync() when the Blur event is triggered and then restoring it using rteObj.RestoreSelectionAsync() after a button is clicked, but I can't seem to get it to work.
I'm currently using RichTextEditor v. 20.2.0.48.
Can you guys please help me accomplish this? Maybe even with an example?
Best regards,
Rúni
| <SfRichTextEditor @ref="rteObj"> <RichTextEditorToolbarSettings Items="@Tools"> <RichTextEditorCustomToolbarItems> <RichTextEditorCustomToolbarItem Name="Symbol"> <Template> <button class="e-btn e-tbar-btn" @onclick="ClickHandler"> <div class="e-tbar-btn-text" style="font-weight: 500;">Insert Text</div> </button> </Template> </RichTextEditorCustomToolbarItem> </RichTextEditorCustomToolbarItems> </RichTextEditorToolbarSettings> <div style="display:block;"><p style="margin-right:10px">The custom command item<b>Insert Emoticons</b> is added to the Toolbar. Click on the command and choose the emoticon you want to include from the popup.</p></div> </SfRichTextEditor> </div> </div> <SfDialog @bind-Visible="@dialogVisible" ZIndex="1000" ShowCloseIcon="false" IsModal="true" Width="45%" Target="#rteSection"> <DialogTemplates> <Header> Insert Emoticons </Header> <Content> <SfComboBox TValue="string" TItem="Countries" @bind-Value="@ComboVal" Placeholder="e.g. Australia" DataSource="@Country"> <ComboBoxEvents TValue="string" TItem="Countries" ValueChange="@onChanged"></ComboBoxEvents> <ComboBoxFieldSettings Value="Name"></ComboBoxFieldSettings> </SfComboBox> </Content> </DialogTemplates> <DialogButtons> <DialogButton Content="Insert" IsPrimary="true" OnClick="OnInsert" Disabled="@disableInsertBtn" /> <DialogButton Content="Cancel" OnClick="DialogOverlay" /> </DialogButtons> <DialogEvents OnOverlayModalClick="DialogOverlay" /> </SfDialog> @code{ SfRichTextEditor rteObj; int currentIndex { get; set; } = -1; int currentTabIndex { get; set; } string activeClass = "e-active"; private bool dialogVisible { get; set; } private bool disableInsertBtn { get; set; } = false; public string ComboVal { get; set; } public class Countries { public string Name { get; set; } public string Code { get; set; } } List<Countries> Country = new List<Countries> { new Countries() { Name = "Australia", Code = "AU"}, new Countries() { Name = "Bermuda", Code = "BM" }, new Countries() { Name = "Canada", Code = "CA" }, new Countries() { Name = "Cameroon", Code = "CM" }, }; public string insertVal { get; set; } public void onChanged(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, Countries> args) { this.insertVal = args.Value; } private List<ToolbarItemModel> Tools = new List<ToolbarItemModel>() { new ToolbarItemModel() { Command = ToolbarCommand.Bold }, new ToolbarItemModel() { Command = ToolbarCommand.Italic }, new ToolbarItemModel() { Command = ToolbarCommand.Underline }, new ToolbarItemModel() { Command = ToolbarCommand.Separator }, new ToolbarItemModel() { Command = ToolbarCommand.Formats }, new ToolbarItemModel() { Command = ToolbarCommand.Alignments }, new ToolbarItemModel() { Command = ToolbarCommand.OrderedList }, new ToolbarItemModel() { Command = ToolbarCommand.UnorderedList }, new ToolbarItemModel() { Command = ToolbarCommand.Separator }, new ToolbarItemModel() { Command = ToolbarCommand.CreateLink }, new ToolbarItemModel() { Command = ToolbarCommand.Image }, new ToolbarItemModel() { Command = ToolbarCommand.Separator }, new ToolbarItemModel() { Name = "Symbol", TooltipText = "Insert Text" }, new ToolbarItemModel() { Command = ToolbarCommand.SourceCode }, new ToolbarItemModel() { Command = ToolbarCommand.Undo }, new ToolbarItemModel() { Command = ToolbarCommand.Redo } }; private async Task ClickHandler() { await this.rteObj.SaveSelectionAsync(); } private async Task OnInsert() { await this.rteObj.RestoreSelectionAsync(); await this.rteObj.ExecuteCommandAsync(CommandName.InsertHTML, this.insertVal); this.dialogVisible = false; } } |
Hi
Thank you very much for the sample and notes. I can definitely work with this.
Your support is great.
Best regards,
Rúni