RichTextBox and SpellChecker

1. Spellchecker locates spelling errors in a RichTextBox but then does not change the text when Change is selected. In the example below all errors in the Facebook paragraph (except for collge, strangely) are handled correctly, but although any misspelled word entered into the RichTextBox are identified, they are not corrected.

2. Assuming the above issue is resolved, is there a way to add the spellchecker as one of the tools in the RTE toolbar?

<div class="container">
    <div id="TextArea" contenteditable="true">
        Facebook is a social networking service headquartered in Menlo Park, California. Its website was launched on February 4, 2004, by Mark Zuckerberg with his Harvard College roommates and fellow students Eduardo, Andrew McCollum, Dustin and Chris Hughes. The fouders had initially limited the websites membrship to Harvard students, but later expanded it to collges in the Boston area, the Ivy League, and Stanford Univrsity. It graually added support for students at various other universities and later to high-school students.
    </div><br />
    <div class="row">
        @{
            List<String> toolsList = new List<string>() { "style", "alignment", "lists", "indenting", "doAction" };
            List<String> style = new List<string>() { "bold", "italic", "underline" };
            List<String> lists = new List<string>() { "unorderedList", "orderedList" };
            List<String> indenting = new List<string> { "outdent", "indent" };
            List<String> doAction = new List<string>() { "undo", "redo" };
        }
        <ej-rte id="myRTEtext" tools-list="toolsList" width="535px" height="340px" create="Oncreate">
            <e-paste-cleanup-settings clean-css="true" list-conversion="true" remove-styles="true" clean-elements="true" />
        </ej-rte>
    </div>
    <ej-spell-check id="SpellCheck" controls-to-validate="#myRTEtext,#TextArea" is-responsive="true">
        <e-dictionary-settings custom-dictionary-url="http://js.syncfusion.com/ejServices/api/SpellCheck/AddToDictionary" dictionary-url="http://js.syncfusion.com/ejServices/api/SpellCheck/CheckWords">
        </e-dictionary-settings>
    </ej-spell-check>
    <ej-button id="CheckButton" width="200px" height="25px" text="Spell check" click="checkErrors" />
</div>
<script>
    function checkErrors() {
        var spellObj = $("#SpellCheck").data("ejSpellCheck");
        spellObj.showInDialog();
    }
    function Oncreate() {
        var css = "html,body{font-family:sans-serif;font-size:16px; }";
        var editorDoc = $("#myRTEtext").ejRTE("instance").getDocument();
        var styleTag = document.createElement("style");
        styleTag.type = "text/css";
        if (styleTag.styleSheet)
            styleTag.styleSheet.cssText = css;
        else
            styleTag.appendChild(document.createTextNode(css));
        editorDoc.head.appendChild(styleTag);
    }
    function onchange(args) {
        var ACtextbox = $("#myRTEtext").data("ejRTE");
        if ($("#comment_Iframe").contents().find("span#selectedtext").length == 0) {
            ACtextbox.pasteContent("<span id='selectedtext'>" + this.selectedTextValue + "</span>"); // add the selected text using span element
        }
        else {
            $("#comment_Iframe").contents().find("span#selectedtext ").text(this.selectedTextValue); //change the text when span element already exists.
        };
    }
</script>

5 Replies

KR Keerthana Rajendran Syncfusion Team April 16, 2018 12:02 PM UTC

Hi Doug,   
   
We can include SpellChecker as custom tool for RTE and check the errors through spell dialog. Please refer to the below given code.   
   
@{   
            List<String> toolsList = new List<string>() { "customTools" };   
        }   
        <ej-rte id="myRTEtext" tools-list="toolsList" width="535px" height="340px"create="Oncreate">   
            <e-content-template>   
                Facebook is a social networking service headquartered in Menlo Park, California. Its website was launched on February 4, 2004, by Mark Zuckerberg with his Harvard College roommates and fellow students Eduardo, Andrew McCollum, Dustin and Chris Hughes. The fouders had initially limited the websites membrship to Harvard students, but later expanded it to collges in the Boston area, the Ivy League, and Stanford Univrsity. It graually added support for students at various other universities and later to high-school students.   
            </e-content-template>   
            <e-tools>   
                <e-custom-tools>   
                    <e-custom-tool name="dialog" tooltip="Click to SpellCheck" css="e-rte-toolbar-icon e-spell" action="showDialog" />   
                </e-custom-tools>   
            </e-tools>   
            <e-paste-cleanup-settings clean-css="true" list-conversion="true" remove-styles="true"clean-elements="true" />   
        </ej-rte>   
<script>   
   function showDialog() {   
        var spellObj = rteObj._rteIframe.data("ejSpellCheck");   
        spellObj.showInDialog();   
    }   
      
    function Oncreate() {   
        var css = "html,body{font-family:sans-serif;font-size:16px; }";   
        var editorDoc = $("#myRTEtext").ejRTE("instance").getDocument();   
        var styleTag = document.createElement("style");   
        rteObj = this;   
        styleTag.type = "text/css";   
        if (styleTag.styleSheet)   
            styleTag.styleSheet.cssText = css;   
        else   
            styleTag.appendChild(document.createTextNode(css));   
        editorDoc.head.appendChild(styleTag);   
        rteObj._rteIframe.ejSpellCheck({   
            dictionarySettings: {   
                dictionaryUrl:"http://js.syncfusion.com/ejServices/api/SpellCheck/AddToDictionary",   
                customDictionaryUrl: "http://js.syncfusion.com/ejServices/api/SpellCheck/CheckWords"   
            },   
            contextMenuSettings: { enable: true },   
            enableValidateOnType: true,   
            enableAsync: false,   
            ajaxDataType: "json",   
            actionSuccess: function (args) {   
                if (args.requestType === "addToDictionary") {   
                    rteObj.setHtml(args.resultHTML);   
                }   
            },   
            contextOpen: function (args) {   
                args.cancel = true;   
            },   
            dialogBeforeOpen: function (args) {   
                if (args.requestType === "alertBeforeOpen") {   
                    args.cancel = true;   
                }   
            }   
        });   
    }   
</script>   
<style>   
    .e-rte-toolbar-icon.e-spell {   
        background:url("https://js.syncfusion.com/demos/web/content/images/rte/Icon_Spellchecker.svg")no-repeat;  //add icon for custom tool   
        background-position3px 5px;   
    }   
</style>   
   
Please refer to the below given UG and demo link.   
   
   
   
Regards,                                                                        
Keerthana.   
  
 



DC Doug Colpitts April 17, 2018 01:53 AM UTC

Thank you very much for this, but I am still having a problem. On a clean cshtml page in my VS 2017 project I have just the code as below, almost exactly the same as your example. When I run it, the icon appears fine on the toolbar of the RTE and brings up the dialog when clicked. However, there is no squiggly red underlining of the incorrect word and there are no Suggestions given. (see spellcheck.png in attached zip).

As well I copied the example you provide in your reply below and when I run it there are also no squiggly red underlining of the incorrect words and there are no Suggestions given.

On another page I have the spellchecker checking textareas instead using the usual method and all works as expected. (see spellcheckok.png in attached zip).
 

<style>
    .e-rte-toolbar-icon.e-spell {
        background: url("https://js.syncfusion.com/demos/web/content/images/rte/Icon_Spellchecker.svg")no-repeat;
        background-position: 3px 5px;
    }
</style>

<div class="container">
    <div class="row">
        @{
            List<String> toolsList = new List<string>() { "style", "alignment", "lists", "indenting", "doAction", "customTools" };
            List<String> style = new List<string>() { "bold", "italic", "underline" };
            List<String> lists = new List<string>() { "unorderedList", "orderedList" };
            List<String> indenting = new List<string> { "outdent", "indent" };
            List<String> doAction = new List<string>() { "undo", "redo" };
        }

        <ej-rte id="AdditionalComment" tools-list="toolsList" width="535px" height="340px" create="Oncreate">
            <e-tools>
                <e-custom-tools>
                    <e-custom-tool name="dialog" tooltip="Click to SpellCheck" css="e-rte-toolbar-icon e-spell" action="showDialog" />
                </e-custom-tools>
            </e-tools>
            <e-paste-cleanup-settings clean-css="true" list-conversion="true" remove-styles="true" clean-elements="true" />
        </ej-rte>
    </div>
</div>

<script>
    function showDialog() {
        var spellObj = rteObj._rteIframe.data("ejSpellCheck");
        spellObj.showInDialog();
    }

    function Oncreate() {
        var css = "html,body{font-family:sans-serif;font-size:16px; }";
        var editorDoc = $("#AdditionalComment").ejRTE("instance").getDocument();
        var styleTag = document.createElement("style");
        rteObj = this;
        styleTag.type = "text/css";
        if (styleTag.styleSheet)
            styleTag.styleSheet.cssText = css;
        else
            styleTag.appendChild(document.createTextNode(css));
        editorDoc.head.appendChild(styleTag);
        rteObj._rteIframe.ejSpellCheck({
            dictionarySettings: {
                dictionaryUrl: "http://js.syncfusion.com/ejServices/api/SpellCheck/AddToDictionary",
                customDictionaryUrl: "http://js.syncfusion.com/ejServices/api/SpellCheck/CheckWords"
            },
            contextMenuSettings: { enable: true },
            enableValidateOnType: true,
            enableAsync: false,
            ajaxDataType: "json",
            actionSuccess: function (args) {
                if (args.requestType === "addToDictionary") {
                    rteObj.setHtml(args.resultHTML);
                }
            },
            contextOpen: function (args) {
                args.cancel = true;
            },
            dialogBeforeOpen: function (args) {
                if (args.requestType === "alertBeforeOpen") {
                    args.cancel = true;
                }
            }
        });
    }
</script>

Attachment: spellcheckscreenshots_331a4a53.zip


KR Keerthana Rajendran Syncfusion Team April 17, 2018 04:26 PM UTC

Hi Doug, 
 
We regret for the inconvenience. 
 
This issue occurs because the proper url is not assigned for dictionaryUrl. Please modify the Url as shown below 
 
function Oncreate() { 
        var css = "html,body{font-family:sans-serif;font-size:16px; }"; 
        var editorDoc = $("#myRTEtext").ejRTE("instance").getDocument(); 
        var styleTag = document.createElement("style"); 
        rteObj = this; 
        styleTag.type = "text/css"; 
        if (styleTag.styleSheet) 
            styleTag.styleSheet.cssText = css; 
        else 
            styleTag.appendChild(document.createTextNode(css)); 
        editorDoc.head.appendChild(styleTag); 
        rteObj._rteIframe.ejSpellCheck({ 
            dictionarySettings: { 
                dictionaryUrl: "http://js.syncfusion.com/ejServices/api/SpellCheck/CheckWords", 
                customDictionaryUrl: "http://js.syncfusion.com/ejServices/api/SpellCheck/AddToDictionary" 
            }, 
            contextMenuSettings: { enable: true }, 
            enableValidateOnType: true, 
            enableAsync: false, 
            ajaxDataType: "json", 
            actionSuccess: function (args) { 
                if (args.requestType === "addToDictionary") { 
                    rteObj.setHtml(args.resultHTML); 
                } 
            }, 
            contextOpen: function (args) { 
                args.cancel = true; 
            }, 
            dialogBeforeOpen: function (args) { 
                if (args.requestType === "alertBeforeOpen") { 
                    args.cancel = true; 
                } 
            } 
        }); 
    } 
 
 
We have prepared a sample for your reference. Please download the sample from 
 
 
Regards, 
Keerthana. 



DC Doug Colpitts April 17, 2018 05:14 PM UTC

Thank you - should have noticed that one myself,
D


KR Keerthana Rajendran Syncfusion Team April 18, 2018 04:18 AM UTC

Hi Doug, 
 
Most Welcome. Please get back to us if you require further assistance on this. We will be happy to assist you. 
 
Regards, 
Keerthana. 


Loader.
Up arrow icon