I have enable pastecleanupsettings prompt for RTE. Prompt Shows on paste content but when Enter Key pressed it doesn't paste content instead it submits my form. Prompt buttons works fine but Enter Key isn't work intended
| <form method="post"> <ejs-richtexteditor id="api" > <e-richtexteditor-pastecleanupsettings Prompt="true"></e-richtexteditor-pastecleanupsettings> </ejs-richtexteditor> <div id="submitbutton"> <button id="submitButton" type="button">Submit</button> </div> </form> |
By Changing Button type submit -> button. How to submit a form ? Adding extra event listener to button and submit form manually that isn't intended because there would have to add extra code everywhere RTE is used and in my application I have too many pages those used RTE. Then there supposed to lot of files to be changed.
| <form method="post"> <ejs-richtexteditor id="api" dialogOpen="Open"> <e-richtexteditor-pastecleanupsettings Prompt="true"></e-richtexteditor-pastecleanupsettings> </ejs-richtexteditor> <div id="submitbutton"> <button id="submitButton">Submit</button> </div> </form><script> function Open(){ if(document.getElementById("api_pasteCleanupDialog").classList.contains("e-popup-open")) { document.getElementById("api_pasteCleanupDialog").addEventListener("keypress", function(args){ args.preventDefault(); }) } } </script> |
RTE Enter key is configured
Hi Khalid,
We have validated your query.
Query 1: Enter key and Shift-Enter Key configured should not submit the form
Yes, you can achieve enter and shift enter not to submit the form.
Query 2: When the dialog is opened the enter action should only perform dialog-specific action
We have created a sample to achieve this use case. We used the "DialogOpen" event, which will be triggered after the dialog is opened. We then added an event listener to the respective dialog element. Now, when the enter key is pressed, the newly added event listener checks for the code value and calls the "preventDefault()" method. After this, we removed the event listener in the "BeforeClose" event, which will be triggered before the dialog is closed.
Please find the attached code snippet and the sample for your reference.
Code Snippet:
@using Syncfusion.EJ2.RichTextEditor
<form method="post"> <ejs-richtexteditor id="api" dialogOpen="onDialogOpen" beforeDialogClose="beforeClose" enterKey="DIV" shiftEnterKey="BR"> <e-richtexteditor-toolbarsettings items="@ViewBag.tools"></e-richtexteditor-toolbarsettings> <e-richtexteditor-pastecleanupsettings Prompt="true"></e-richtexteditor-pastecleanupsettings> </ejs-richtexteditor> <div id="submitbutton"> <button id="submitButton" type="submit">Submit</button> </div> </form> <script> var dialogElem; function onDialogOpen(args) { var tableDialog = document.getElementById("_tabledialog"); var pasteCleanupDialog = document.getElementById("api_pasteCleanupDialog"); var insertLinkDialog = document.getElementById("_rtelink"); var dialog = (tableDialog && tableDialog.classList.contains("e-dialog")) ? tableDialog : (pasteCleanupDialog && pasteCleanupDialog.classList.contains("e-dialog")) ? pasteCleanupDialog : (insertLinkDialog as&& insertLinkDialog.classList.contains("e-dialog")) ? insertLinkDialog : null; if (dialog) { dialog.addEventListener('keypress', handleEnterKeyPress); dialogElem = dialog; } } function handleEnterKeyPress(args) { if (args.code === "Enter") { args.preventDefault(); console.log("Enter action prevented"); } } function beforeClose() { if (dialogElem) { dialogElem.removeEventListener('keypress', handleEnterKeyPress); } } </script> |
NOTE: Please check the id for the respective dialog element variables used above in your application.
Regards
Gokulraj Devarajan
Attachment: RTE_Inside_Form_5c49752.zip