This is a migrated thread and some comments may be shown as answers.

How to supress RadSpell when all words are spelt correctly?

8 Answers 117 Views
Spell
This is a migrated thread and some comments may be shown as answers.
taeho
Top achievements
Rank 1
taeho asked on 11 Nov 2008, 10:09 PM
Thanks for your support first of all,

I have a textbox to check, the textbox has onBlur="GetRadSpell(spellCheckClientId).startSpellCheck();"
Now if Sydney (which is correct) is typed and go to the next input box, I don't want to display radSpell windows.
But when Sydny is typed then the windows should appear to allow users to be aware.

Is that possible?

Thanks

Toby

8 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 14 Nov 2008, 04:10 PM
Hi Toby,

I think that the following KB article could be helpful for your scenario: Using SpellCheckService to derermine if there are mistakes in the editor's content.

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
taeho
Top achievements
Rank 1
answered on 17 Nov 2008, 02:15 AM
Thank you for your answer.
I read the article and followed it but I am getting some problems.
I gathered that I need to use SpellCheckService.
I am using
Runtime version v2.0.50727
Version 2008.3.1105.20

But having problem registering SpellCheckService.
I did

<%@ Register TagPrefix="rad" Namespace="Telerik.WebControls" Assembly="RadSpell" %>
Or
<%@ Register TagPrefix="rad" Namespace="Telerik.Web.UI" Assembly="RadSpell" %>
OR
<%@ Register TagPrefix="rad" Namespace="Telerik.WebControls" Assembly="Telerik.WebControls" %>
OR
<%@ Register TagPrefix="rad" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<rad:SpellCheckService id="SpellCheckService1" runat="server"></rad:SpellCheckService>

It is saying SpellCheckService is not known element.

Could you please help???

Thanks





0
Rumen
Telerik team
answered on 20 Nov 2008, 01:17 PM
Hi Taeho,

For your convenience, I created and attached a sample fully working project that demonstrates the solution provided in the KB article.


Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
taeho
Top achievements
Rank 1
answered on 21 Nov 2008, 04:00 AM
Hi thanks for your reply.
However, I am using a normal textbox and radSpell control attached to it.

Thanks
0
Rumen
Telerik team
answered on 25 Nov 2008, 11:10 AM
Hi Taeho,

You can use the RadEditor control and its ajax spellchecking engine to achieve your scenario. Here is some sample code:

<script type="text/javascript"
var spellService = null
function checkWord(word) 
    if (!spellService) 
    { 
        spellService = $find("<%= spellEditor.ClientID %>").get_spellCheckService(); 
        spellService.add_complete(spellCallback); 
    } 
    spellService.spellCheck(word); 
function spellCallback(sender, args) 
    if (args.badWords.length > 0) 
    { 
        var badWord = args.badWords[0]; 
        var suggestions = badWord.suggestionsString; 
        // suggestions now holds an array of possible spellings for the misspelled word 
    } 
</script> 
<input type="button" id="launchButton1" value="Spell Check" onclick="javascript:checkWord('teszt');" /><br /> 
<div style="display:none"
<telerik:RadEditor ID="spellEditor" runat="server"
<Tools><telerik:EditorToolGroup><telerik:EditorTool Name="ajaxspellcheck" /></telerik:EditorToolGroup></Tools></telerik:RadEditor> 
</div> 

As you can see, I use a hidden RadEditor control with just the AjaxSpellCheck tool. The checkWord() function initiates an ajax request for the word you wish to check and the response is handled by the spellCallback() function. If the word was not in the spell check dictionary, the suggestions varialbe will hold an array of suggestions you can use in your search dropdown.



Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
burn
Top achievements
Rank 2
answered on 19 Jan 2009, 05:26 PM

Hello,

I am using the suggested SpellCheckService method (see below), and it's working great.

Is it possible to retrieve the id of the html element being spellchecked? (In my case a hidden input field from the callback function)
Something like

spellcallback(sender, args, id); 


I have multiple hidden input fields that I'm checking for spelling errors and would like to know which fileds failed and which passed. As the callbacks are assynch I can't rely on the order of the callback.

TIA,

Anders

<script type="text/javascript">    
var spellService = null;    
function checkWord(word)    
{    
    if (!spellService)    
    {    
        spellService = $find("<%= spellEditor.ClientID %>").get_spellCheckService();    
        spellService.add_complete(spellCallback);    
    }    
    spellService.spellCheck(word);    
}    
function spellCallback(sender, args)    
{    
    if (args.badWords.length > 0)    
    {    
        var badWord = args.badWords[0];    
        var suggestions = badWord.suggestionsString;    
        // suggestions now holds an array of possible spellings for the misspelled word    
    }    
}    
</script>    
<input type="button" id="launchButton1" value="Spell Check" onclick="javascript:checkWord('teszt');" /><br />    
<div style="display:none">    
<telerik:RadEditor ID="spellEditor" runat="server">    
<Tools><telerik:EditorToolGroup><telerik:EditorTool Name="ajaxspellcheck" /></telerik:EditorToolGroup></Tools></telerik:RadEditor>    
</div>    
 
0
Rumen
Telerik team
answered on 20 Jan 2009, 02:22 PM
Hi burn,

Please, find below a sample code example which demonstrates how to pop up a message which fields contains errors:

<script type="text/javascript">  
var spellService = null;  
var currentIndex = 0
var fieldsWithErrors = []; 
var fields = []; 
 
function checkFields()  
{      
    //Set which elements should be checked 
    fields = ["field1", "field2", "field3", "field4"]; 
     
    //Initialize spellcheck 
    if (!spellService)  
    {  
        spellService = $find("<%= spellEditor.ClientID %>").get_spellCheckService();  
        spellService.add_complete(spellCallback);  
    }  
         
    //Get text 
    var text = $get(fields[currentIndex]).value; 
    spellService.spellCheck(text);  
}  
 
 
function spellCallback(sender, args)  
{  
    if (args.badWords.length > 0)  
    {  
        var badWord = args.badWords[0];  
        var suggestions = badWord.suggestionsString;  
        //suggestions now holds an array of possible spellings for the misspelled word  
         
        //Add this element to the bad words array 
        fieldsWithErrors[fieldsWithErrors.length] = fields[currentIndex];                 
    }  
     
    //Increase counter 
    currentIndex++; 
         
    //If currentIndex < fields.length - go on 
    if (currentIndex < fields.length
    {                 
        var text = $get(fields[currentIndex]).value; 
        spellService.spellCheck(text);  
    } 
    else //Display results 
    { 
        alert("There are errors in " + fieldsWithErrors); 
     
        //Reset variables for next spellcheck run 
        currentIndex = 0
        fieldsWithErrors  = []; 
    } 
         
}  
</script>  
 
<input type="button" id="launchButton1" value="Spell Check" onclick="javascript:checkFields();return false;" /><br />  
 
<textarea id="field1"> This text is correct</textarea> 
 
<textarea id="field2"> Thiz tekst is rong</textarea> 
 
<textarea id="field3"> This text is correct</textarea> 
 
<textarea id="field4"> Thiz tekst is rong</textarea> 
<div style="display:none">  
<telerik:RadEditor ID="spellEditor" runat="server">  
<Tools><telerik:EditorToolGroup><telerik:EditorTool Name="ajaxspellcheck" /></telerik:EditorToolGroup></Tools></telerik:RadEditor>  

For your convenience I have attached my test page.

Feel free to enhance the code to fit your specific scenario.

Regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
burn
Top achievements
Rank 2
answered on 20 Jan 2009, 09:18 PM
Again the Telerik Team comes through. Thank you for the code snippet works to perfection.

Anders.
Tags
Spell
Asked by
taeho
Top achievements
Rank 1
Answers by
Rumen
Telerik team
taeho
Top achievements
Rank 1
burn
Top achievements
Rank 2
Share this question
or