Monday 31 October 2011

Spell Check within InfoPath 2010 Browser Forms

One thing I have never understood is the lack of a spell check facility within InfoPath Form Services forms. SharePoint has a spell checking web service which can be viewed at “_vti_bin/SpellCheck.asmx” so why can this not be used ?

Well it can and here’s how:

Override a list form into an InfoPath form via the Customise form options:

image

Once saved select the Form Web Parts and edit the New Form as follows: Add a Content Editor Web Part to the top; edit the HTML and add the following:

   1:  <script language="javascript" src="/_layouts/1033/SpellCheckEntirePage.js?rev=zYQ05cOj5Dk74UkTZzEIRw%3D%3D" type="text/javascript"></script>
   2:  <script language="javascript" type="text/javascript">
   3:     function CheckSpelling()
   4:     {
   5:        SpellCheckEntirePage('/_vti_bin/SpellCheck.asmx', '/_layouts/SpellChecker.aspx');      
   6:     }
   7:  </script>
   8:   
   9:  <a onclick="CheckSpelling();" href="javascript:"><img alt="Spell Check" src="_layouts/1033/images/RTE2SPCHK.GIF" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px"/></a>
  10:   

The form spell check relies on the SpellCheckEntirePage JavaScript file so this must first be included. All that is left to do is call it.

Save and close the page and now should end up with something that looks as follows:

Untitled

Press the spell check button and the form is spell checked. Should you not want to spell check a specific field then you will need to exclude the controls first by setting the attribute excludeFromSpellCheck to true.

It would be nice to package this into a feature for the Ribbon but I will leave this as an exercise for the reader.

2 comments:

  1. Now this is a very useful post. Any luck with getting this to work on an enhanced rich text document?

    ReplyDelete
  2. Dude, thank you. I was searching for a simple way to add browser spell-check for InfoPath forms - this is exactly what I needed!!

    ReplyDelete