Javascript Events and API for ASPNetSpell
ASPNetSpell has a full JavaScript API allowing the advanced developer to capture events and modify behaviour of spell-checkers at client runtime.
This demo shows the Javscript API capturing the onDialogOpen and onChangeWord (as-you-type) events.
ASPNetSpell has a full JavaScript API allowing the advanced developer to capture events and modify behaviour of spell-checkers at client runtime.
Simple .Net Event Model - OnSpellCheckComplete
If you just want to submit a form upon spell-check dialog completion - see the ASP.Net SpellButton Event - OnSpellCheckComplete
JavaScript Event Model
Each SpellButton and SpellTextArea at the server side are paired with a clientside instance of LiveSpellOject - a Javascript class documented below.
- You can acess this API using the JavaScript identifier JavaScriptId for each object
- E.g.<%= SpellButton1.JavaScriptId%>
- This code must be placed AFTER the last <form> tag on the page
<form id="form1" runat="server">
<ASPNetSpell:SpellTextBox ID="SpellTextBox1" runat="server">
...
</ASPNetSpell:SpellTextBox>
<ASPNetSpell:SpellButton ID="SpellButton1" runat="server" />
</form>
<script type='text/javascript' >
// This script must come after the end of the < /form > tag
var mySpellButton= <%=SpellButton1.JavaScriptId%>;
mySpellButton.onDialogOpen = function(){ alert("onDialogOpen Dialog Event fired by SpellButton1")}
var mySpellTextBox= <%=SpellTextBox1.JavaScriptId%>;
mySpellTextBox.onChangeWord = function(){ alert("onChangeWord As-You-Type Event fired by SpellTextBox1")}
</script>
Events can apply to both as-you-type and in dialog spellchecking as needed:
- onDialogOpen
- onDialogComplete
- onDialogCancel
- onDialogClose
- onChangeLanguage
- onIgnore
- onIgnoreAll
- onChangeWord
- onChangeAll
- onLearnWord
- onLearnAutoCorrect
- onUpdateFields
Full JavasScpit Object Reference
Class LiveSpellObject
Defined in /ASPNetSpellInclude/include.js
<script src="/ASPNetSpellInclude/include.js' type='text/javascript'></script>
<script type='text/javascript'>
// E.g.
var mySpell = new LiveSpellInstance();
mySpell.Fields = "ALL"
mySpell.ServerModel="aspx"
mySpell.DrawSpellImageButton()
mySpell.ActivateAsYouType()
</script>
| Core Properties | |||
|---|---|---|---|
| CaseSensitive | Bool | True | Consider case mistakes when spellchecking? |
| CheckGrammar | Bool | True | Check for structural grammar errors such as repeated words, and sentence casing. |
| CSSTheme | String | "classic" | Theme for the spell-checker UI context menu and spelling dialog window. Maps to a folder name within /ASPNetSpellInclude/themes/ |
| Fields | String | "ALL" | Sets the html elements to be spell-checked by this instance.
|
| FormToSubmit | String | "" | A form id to submit upon successful spellchecking using the dialog. |
| IgnoreAllCaps | Bool | True | Ignore ALL CAPITALIZED words |
| IgnoreNumeric | Bool | true | gnore strings with numbers in them which are often product codes or serial numbers.
|
| Language | String | "English (International)" | Dictionary language to be used for spellchecking.
|
| UserInterfaceLanguage | String | "en" | Translation ANSI language code for the spellchecker dialogue and context menu.
|
| ServerModel | String | "php" | Server hypertext processing language. Needs to be set to "aspx" or "asp.net" for .net applications |
| Advanced Setup Properties | |||
| CustomOpener | function | null | Set a custom function which will override the regular spell-checker window opening method.
|
| CustomOpener | function | null | Set a custom function which can be set to override the regular spell-checker window opening method. |
| CustomOpenerClose | function | null | Set a custom function called when spellchecking in a CustomOpener scenario is completed. |
| Delay | integer | 888 | Delay in milliseconds between the user finishing typing and As-You-Type fields having their spelling re-validated. |
| WindowMode | String | "modal" | Sets the behavior of the spellchecker dialog to either:
|
| Strict | Bool | true | Enforces "Banned Words" and "Enforced Corrections" such that they cannot be ignored. |
| ShowSummaryScreen | Bool | true | Shows a summary of statistics after a spell checker dialog has successfully finished. |
| ShowMeanings | Bool | true | Shows the meaning of words and thesaurus using the "Lookup meaning..." link in the spell checker dialog.
|
| MeaningProvider | String | "http://www.thefreedictionary.com/{word}" | The URL expression that the meaning lookup will go to for definitions and synonyms |
| UndoLimit | Integer | 20 | Maximum remembered levels of user undo. |
| HiddenButtons | String | "" | A "comma,separated,list" of buttons to be removed from the spell-checker dialog and context menu - identified by their id |
| HiddenButtons | String | "" | A "comma,separated,list" of buttons to be removed from the spell-checker dialog and context menu - identified by their id |
| HiddenButtons | String | "" | A "comma,separated,list" of buttons to be removed from the spell-checker dialog and context menu - identified by their id |
| Methods | |||
| checkInWindow() | Spell checks your Fields in a pop-up dialog window. | No Arguments | Returns: null |
| checkInSitu() | Spell checks your text-area fields in place using red-wiggly-underlining and a context menu. | No Arguments | Returns: null |
| activateAsYouType() | All textarea fields named in the Fields property will now automatically validate spelling in context when their value changes due to user interaction. | No Arguments | Returns: null |
| pauseAsYouType() | Pauses the behavior started by the activateAsYouType function | No Arguments | Returns: null |
| Rendering Methods | |||
| url() | Returns the URL used to open the spell-checker dialog window. | No Arguments | Returns: String |
| url() | Returns the URL used to open the spell-checker dialog window. | No Arguments | Returns: String |
| DrawSpellButton([inPlace] [,text] [,Class] [,style] ) | document.writes a SpellButton | Arguments: see SpellButton function | Returns: null - writes an element to the HTML DOM |
| DrawSpellImageButton ([inPlace] [,image] [,rollover] [,text] [,Class] [,style]) | document.writes a SpellImageButton | Arguments: see SpellImageButton function | Returns: null - writes an element to the HTML DOM |
| DrawSpellLink([inPlace] [,text] [,Class] [,style] ) | document.writes a SpellLink | Arguments: see SpellLink function | Returns: null - writes an element to the HTML DOM |
| SpellButton([inPlace] [,text] [,Class] [,style] ) | Returns an HTML string for a form button that will open a spellchecker. | Arguments:
| Returns: (string) of the button's full html |
| SpellImageButton ([inPlace][,image,][,rolloverImage][,Class][,style]) | Returns an HTML string for an image with rollover effect that will open a spellchecker. | Arguments:
| Returns: (string) of the image button's full html |
| SpellLink([inPlace] [,text] [,Class] [,style] ) | Returns an HTML string for a hyperlink that will open a spell-checker. | Arguments:
| Returns: (string) of the link's full html |
| Events | |||
| onDialogOpen() | No Arguments | Spellchecker dialog is opened. | |
| onDialogComplete() | No Arguments | Spellchecker dialog completes spellchecking all words. | |
| onDialogCancel() | No Arguments | Spellchecker dialog is cancelled before spellchecking all words. | |
| onDialogClose() | No Arguments | Spellchecker dialog closes for any reason. | |
| onChangeLanguage(Language) | Arguments: Language (string) | User changes the selected dictionary language in either a dialog window or context menu. | |
| onIgnore(Word) | Arguments: Word (string) | A word is ignored by the user. | |
| onIgnoreAll(Word) | Arguments: Word (string) | The users tells the spellchecker to "Ignore All" | |
| onChangeWord(From, To) | Arguments: From(string), To (string) | The user corrects a word's spelling. | |
| onChangeAll(From, To) | Arguments: From(string), To (string) | The user corrects a words spelling and applies that change globally across all current fields. | |
| onLearnWord(Word) | Arguments: Word (string) | A words is added to the dictionary. | |
| onLearnAutoCorrect(From, To) | Arguments: From(string), To (string) | A words is added to the user's own personal auto-correct. | |
| onUpdateFields(arrayOfFieldIds) | Arguments: arrayOfFieldIds(Array) An array of strings of the fields which have been updated. | A form field is updated due to spellchecking. The fields affected are listed in the arrayofFieldIds array. | |
The AJAX API
The Ajax API allows your to make Asynchronous server requests for spellcheciing from the client page without refreshing the browser.
| Ajax Methods | |||
|---|---|---|---|
| AjaxSpellCheck(word, makeSuggestions) | Arguments: (string) word, (bool) makeSuggestions | Returns: null - results are sent to the onSpellCheck event | Makes an AJAX request to spell-check the word. Spelling suggestions are only returned to onSpellCheck if makeSuggestions is true. |
| AjaxSpellCheckArray(arrayOfWords, makeSuggestions) | Arguments: (array) arrayOfWords, (bool) makeSuggestions | Returns: null - results are sent to the onSpellCheck event | ajaxSpellCheckArray functions much as ajaxSpellCheck excapt an array of words is spellchecked. Spelling suggestions are only returned to onSpellCheck if makeSuggestions is true. |
| AjaxDidYouMean(inputString) | Arguments: (string) inputString | Returns null - results are sent to the onDidYouMean event | Requests the most likely "Did You Mean..." search query string for inputString. |
| AJAX Events & Callbacks | |||
| onSpellCheck (word, spelling, reason, suggestions) | Arguments:
| Callback function for the ajaxSpellCheck method.
| |
| onDidYouMean (suggestion, original) | Arguments:
| Callback function for the AjaxDidYouMean function. | |
Installation outside of ASP.Net Applications
The JavaScript API allows developers the choice to use all of ASPNetSpell's functionality using JavaScript as the integration language... anywhere on an IIS server that supports ASP.net.
- Ensure that /ASPNetSpellInclude/ is installed in the website root (and test this installation using the examples in /ASPNetSpellInclude/debug-test-scripts/).
- Use JavaScript to implement ASPNetSpell.
e.g.
SourceCode:<script src="/ASPNetSpellInclude/include.js' type='text/javascript'></script>
<script type='text/javascript'>
var mySpell = new LiveSpellInstance();
mySpell.Fields = "ALL"
mySpell.ServerModel="aspx"
mySpell.DrawSpellImageButton()
mySpell.ActivateAsYouType()
</script>
