Wednesday, 29 September 2010

ASP.NET: Web Application Spell Checking with jQuery and AtD (After the Deadline)

Why did I need it?
In a recent project, we had a very large form with wizard steps and several multiline text area controls. The form was submitted to senior managers, so the requirement was raised to provide some kind of automated spell checking functionality.

Given that this is a web application, it wasn't obvious which solution to choose. You can ask you users to install browser plugins which will check spelling, but this isn't really pratical since very few people would actually do it. Or you can install a full third party application on your server and use some kind of AJAX call to check spelling.

If a spell checker does not make good suggestions to fix spelling or grammar mistakes, then it becomes pointless. So we needed something with a good comprehensive dictionary and it had to be quick.

After some rooting around and consideration of third party products and also possibly somehow piggybacking on SharePoint's spell checking service, I found a product called AtD (After the Deadline).

What is AtD?
AtD is an open source solution which you can plug into your website using the wonderful jQuery (though it also offers other spell checking methods). It seems like an odd name to me, but apparently AtD is named after a similarly titled blog in the New York Times.

It's a fantastic product and only takes a short time to set up. Using the jQuery version which I chose, it runs client side and will highlight spelling and grammar errors, and provide a good set of suggestions to fix them. It's quick, user friendly and it even works in IE6. Use this link to download the source code and view a couple of tutorials, though the tutorial I found most valuable was this one:

Demo 3

Here is Demo 3 in action:

You can use that page to try out AtD for yourself, and if you view its source you can follow the simple step by step instructions to get started.

There are tutorials on the site, but basically you either link to the source code and css, or embed it in your project, use a little bit of jQuery code to assign the spell checker to each textarea on your page, do any layout customisations you need and wham bam - it works. You don't need to add any markup to your existing page, the jQuery will do the legwork for you.

It wasn't all plain sailing…
I did have a small problem in getting up and running with AtD. What's the problem I most often come up against in web development? That's right, Internet Explorer.

Basically the issue was in getting the spell checker buttons to float to the right hand side of the textarea controls (to me, this seems the most obvious place to put them), but by default AtD will add the spell checker button to the top right hand side of the textarea using a dynamically rendered span element.

I thought it'd be easy to get the spell checker button to sit where I needed it simply by modifying the css to make the spelling button float to the right of the textbox. This worked perfectly in Firefox, but in IE when you float the button, the onclick behaviour inexplicably stops working, thus rendering the whole thing useless. That was no good.

Of course, you can edit the css used to render the AtD elements. So I played around with it for a while and ended up changing the default CSS for the spelling buttons to look like this:


.AtD_proofread_button
{
width: 14px;
height: 14px;
background-image: url('../images/writing.gif');
margin-left: 465px;
position: absolute;
}
.AtD_edit_button
{
width: 14px;
height: 14px;
background-image: url('../images/editing.gif');
margin-left: 465px;
position: absolute;
}

I removed the display:block property, added position: absolute and added a left margin which is roughly equivalent to the width of the textarea controls in my project. This meant that the buttons sat nicely alongside the textboxes, and the absence of a float property meant that IE and Firefox would render the whole thing nicely.

Conclusion
After the Deadline makes for a superbly straightforward and lightweight spell checking solution for web applications which adds real value. I'll certainly be using this in any future web project where spell checking is required.

6 comments:

Stephen said...

Thanks Phil!
I will give the AtD spell checker a shot.

Pittsburgh Food Scene said...

Did you have to install ADT in your own server, too?

Phil said...

Yes, I had to install it on our server to avoid transmitting sensitive information to someone else's server!

But it works better that way anyway, and with lower latency!

Sorry the demo on my blog post is so poor, but you get the idea!

rspring said...

Am I missing something or is AtD a php based solution? How did you get it to work in a .NET solution? The article talks about a minor css tweak, but nothing about the changes for .NET?

Thorsten said...

Hi,

the title of this one is ASP.NET: Web ... but that Demo is on server side directing to PHP script.

So, do you have such an Proxa for AtD for ASP.Net or is the title here missleading?

Thanks,

Thorsten

Manish Patel said...

Phil

Is there a demo code in .net that will give an idea how to implement it? I dont want to use their service. I want to install it on our server.