To force the spell checker to run before the form is submitted, it's necessary to divert the submit button's onclick to a function that will launch the spell check, and then when the spell check finishes, resubmit the form.
1. Add this Javascript block to the page
<script> function AutoCheckClass(startFunction){ this.hasRun = false; this.startFunction = startFunction; this.runSpellCheck = runSpellCheck; this.saveButton; this.onFinish = onFinish; function onFinish(){ this.saveButton.click(); } function runSpellCheck(saveButton){ this.saveButton = saveButton; eval(this.startFunction); this.hasRun = true; } }
var leftAutoChecker = new AutoCheckClass("popUpCheckSpellingrswl1('rsTCIntrswl1')"); function handleLeftSave(saveButton){ if(leftAutoChecker.hasRun) return true; else { leftAutoChecker.runSpellCheck(saveButton); return false; } }
</script>
2. Set the id and finishedListener properties of the launcher tag
<RapidSpellWeb:rapidSpellWebLauncher rapidSpellWebPage="RapidSpellCheckerPopUp.jsp" textComponentName="myForm.sourceTextBox" id="rswl1" finishedListener="leftAutoChecker.onFinish" />
Note that the ID matches the string used above
var leftAutoChecker = new AutoCheckClass("popUpCheckSpellingrswl1('rsTCIntrswl1')");
3. Add the following onclick to your submit button
<input type='submit' onclick="return handleLeftSave(this);">
That should then cause the spell check to popup before the form is submitted. The complete code, for 'exampleTextBox2-Simple.jsp' is below.
<%@ taglib uri="/WEB-INF/RapidSpellWeb.tld" prefix="RapidSpellWeb" %>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <HTML> <head> <script> function AutoCheckClass(startFunction){ this.hasRun = false; this.startFunction = startFunction; this.runSpellCheck = runSpellCheck; this.saveButton; this.onFinish = onFinish; function onFinish(){ this.saveButton.click(); } function runSpellCheck(saveButton){ this.saveButton = saveButton; eval(this.startFunction); this.hasRun = true; } }
var leftAutoChecker = new AutoCheckClass("popUpCheckSpellingrswl1('rsTCIntrswl1')"); function handleLeftSave(saveButton){ if(leftAutoChecker.hasRun) return true; else { leftAutoChecker.runSpellCheck(saveButton); return false; } }
</script> </head> <BODY >
<% if(request.getParameter("fMessage") == null){ %> <p>Simple example usage of RapidSpell Web
<form action='exampleTextBox2-Simple.jsp' method='post' name='myForm' id='myForm' runat='server'> <input type='hidden' name='fMessage' value='complete'> <textarea name="sourceTextBox" wrap='true' cols='40' rows='10'>This is some sample text with daliberate spelling errars</textarea> <br>
<!-- NOTE: The id is set to rswl1 to match popUpCheckSpellingrswl1('rsTCIntrswl1') above --> <RapidSpellWeb:rapidSpellWebLauncher rapidSpellWebPage="RapidSpellCheckerPopUp.jsp" textComponentName="myForm.sourceTextBox" id="rswl1" finishedListener="leftAutoChecker.onFinish" />
<input type='submit' onclick="return handleLeftSave(this);"> </form>
<% } else { %>
Text entered was: "<%=request.getParameter("sourceTextBox")%>"
<% } %>
</body> </HTML>
|