Welcome Guest Search | Active Topics | Sign In | Register

Using the SpellChecker in a Save button Options
John
Posted: Wednesday, April 22, 2009 10:13:17 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2009
Posts: 4
I would like to use the SpellChecker in a Save button on a form to check several fields. If the user accepts the spell check the save is to continue otherwise the save is to be cancelled. How do I do this?

Thanks
eo_support
Posted: Thursday, April 23, 2009 9:30:51 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Thanks for posting in the forum. I am not exactly sure what you meant by "accepts the spell check". What the spell checker does is to present you a list of "suggestions", so that you can pick one from them. The suggestion may not contain what you really wanted; in that case you are also allowed to manually type in the correct form.

As such spell check is different than "auto correction". It is not a simple yes or no question to the end user. It warns the mistake, presents the options and requires more user input such as selecting a word or type in the correct form.

You can take a look of how spell checker works at here:

http://demo.essentialobjects.com/Default.aspx?path=SpellChecker\_i0\_i0

With this in mind, if you can let us know exactly what you would regard as "accepting the spell check" in this process, we will try to work out something for you.

Thanks
John
Posted: Thursday, April 23, 2009 6:03:27 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2009
Posts: 4
Sorry for not wording the question correctly.

I have a save button on a form, if I set the StartButton property of the SpellChecker to the id of this button then when the user clicks the button the spell checker dialog popups up and I can spell check some of the fields. So far so good, however when I click the Close button of the spell checker dialog the code in the Save button does not run. What I want to be able to do is put two buttons (an "OK" and a "Cancel") on the spell checker dialog. If the user clicks the "OK" button the code in the Save button runs and if the user clicks the "Cancel" button the code in the Save button does not run.

Thanks

John
eo_support
Posted: Thursday, April 23, 2009 8:23:45 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

This is very easy to do. Please follow these steps:

1. Configure the SpellChecker and SpellCheckerDialog as usual;
2. Right click SpellCheckerDialog control, then select Edit Template -> Content Template. This will switch the dialog into template mode and fills its ContentTemplate with the default layout template;
3. Add a Button control into the template, this will be your "Save" button;
4. Handle the OK button's Click event as usual;

Basically the only special part is that you need to put the button inside the dialog, which is achieved by step 2 and step 3.

Thanks!
John
Posted: Thursday, April 23, 2009 11:34:49 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2009
Posts: 4
Hi

I added a button to the SpellCheckerDialog control and put my save code in the click event but there are a couple of problems:

1. I need to check several fields, however the changes to the last field don't take That is, if I change spelling errors in the last field and then click the "Accept" button the changes are not not applied. For earlier fields making changes are applied when it goes to the next field to check.

2. If there are no spelling errors I get a "Spell Check Completed" message box and when I click OK the dialog disappears and I don't get a chance to click my "Accept" button to run the save code.

Thanks

John
eo_support
Posted: Friday, April 24, 2009 9:10:38 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

To resolve the first problem, place the following code after the SpellChecker and SpellCheckerDialog:

Code: HTML/ASPX
<script type="text/javascript">
//Get the JavaScript code that can be used to simulate Save button click
var postBackJS ="<%=GetPostBackEventReference(SpellCheckerDialog1.ContentContainer.FindControl("btnSave"))%>";

//Handle the Save button's client side onclick event
var button = document.getElementById('<%=SpellCheckerDialog1.ContentContainer.FindControl("btnSave").ClientID%>');
button.onclick = function()
{
    //Close the SpellCheckerDialog first. This ensures the result is stored
    //back to the textbox
    var spellCheckerDialog = eo_GetObject("SpellCheckerDialog1");
    spellCheckerDialog.close();

    //Trigger the post back
    eval(postBackJS);				
}
</script>


To resolve the second problem, place the following code before the SpellChecker and SpellChecker dialog:

Code: HTML/ASPX
<script type="text/javascript">
function msg_handler(ctrl, msgName)
{
    if (msgName == "no_error")
        eval(postBackJS);
}
</script>

You would also set the SpellChecker's ClientSideOnMessage to "msg_handler". This way when the SpellChecker wants to display a message, it calls your "msg_handler", which checks whether the message is "Spell Check Completed", if it is, then post back directly.

Hope this helps.

Thanks!

John
Posted: Tuesday, April 28, 2009 6:10:33 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2009
Posts: 4
Hi

Thanks for your help with this problem, I now have the button working as I would like. However I have discovered another problem. I have two buttons on the form a "Save" and a "Save and Close" and if I associate the spell checker with both, I can do the spell check and after clicking the "Accept" button run the "Save" code but I don't know which button the user clicked to get to this point, so I don't know whether to close the form or not. How do I determine which one of these buttons (the "Save" or the "Save and Close") the user clicked?

Best regards

John
eo_support
Posted: Tuesday, April 28, 2009 6:26:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

I am assuming that by "associate the spell checker with both", you meant setting the SpellChecker's StartButton. If that's the case, I do not think you can do it at all --- You can only specify one button as the StartButton.

In order to use two buttons, you will need to use JavaScript to handle the button's onclick event. Inside your button's client side onclick handler you will call this function to start the SpellChecker:

http://doc.essentialobjects.com/library/1/jsdoc.public.spellchecker.start.aspx

The code will be something like this:

Code: JavaScript
eo_GetObject("SpellChecker1").start();


If you are not familiar with our client side JavaScript interface, you can take a look of this topic:

http://doc.essentialobjects.com/library/1/clientapi_howto.aspx

This way the two buttons have no direct relationship with the SpellChecker except that you are calling the SpellChecker's start method to start the spell checking when it is clicked. Since everything is completely in your code, you will have full control of what to do when the button is clicked and distinguishing the two should no longer be an issue.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.