Dialog Validator

Using the dialog spell checker as a client-side validator.

  1. Setup dialog checking per this topic.
  2. Drag RapidSpell-AYT.js from Solution Explorer into the page, this will add a <script src="RapidSpell-AYT.js"></script> tag to the page with the correct path.
  3. Add the validation function to a Javascript block.
    rapidSpell.ayt_aytEnabled = false;//disable inline checking
    rapidSpell.ayt_staticMode = true; //disable inline checking
    function validateSpelling(oSrc, args) {
    	//Check if spell check already ran.
    	for (var i = 0; i < rsw_rapidSpellControls.length; i++) {
    		if (rsTCInt[rsw_rapidSpellControls[i]].tbName == oSrc.controltovalidate && rsTCInt[rsw_rapidSpellControls[i]].hasRun) {
    			args.IsValid = true;
    			return;
    		}
    	}
    
    	//we import RapidSpell-AYT.js to be able to use RapidSpellCheckerClient
    	var rapidSpellChecker = new RapidSpellCheckerClient(rapidSpell.ayt_helperURL);
    	rapidSpellChecker.config = rsw_getConfigurationObject('default');
    	var result = rapidSpellChecker.Check(args.Value);
    	args.IsValid = result.numberOfErrors == 0;
    }
    

    This will check if spell checking has been performed on the text box that is validating, and if not will check it for errors using the RapidSpellCheckerClient class.
  4. Add an asp:CustomValidator to the page for each text box.
    <asp:CustomValidator id="CustomValidator1"  runat="server" ControlToValidate="TextBox1" EnableClientScript='true' 
                 ErrorMessage="There are spelling errors and spell check hasn't been performed." 
                 ClientValidationFunction="validateSpelling">
                </asp:CustomValidator>
    
  5. Tip: it appears that generally (with or without RapidSpell) the .NET CustomValidator, when using a ClientValidationFunction, does not work in strict page mode (i.e.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">) - please do conduct your own tests.