Home Search Member List Faq Register Login  
UltimateSpell
Re: Additonal Java Script with Spell as you type

Thread Starter: montoya.juanc   Started: 10-28-2007 3:21 AM   Replies: 8
 Karamasoft Support Forums » General Discussions » UltimateSpell » Re: Additonal Java Script with Spell as you type
 Printable Version    « Previous Thread   Next Thread »
  28 Oct 2007, 3:21 AM
montoya.juanc is not online. Last active: 11/12/2007 4:13:30 AM montoya.juanc

Top 10 Posts
Joined on 10-28-2007
Posts 5
Additional Java Script with Spell as you type

I am working on an auto complete function, database driven. I am trying to use AJAX and web services to accomplish the task. I also want to keep the "spell as you type" functionallity

Everything is working fine, the problem I have is that UltimateSpell is placing DIVS on top of the textboxes, and when I modify the textbox values via JavaScript the text on the div is not updated. The code to understand the behavior is presented below:

<script type="text/javascript" language="javascript">
function <%=UltimateSpell1.ClientID%>_OnLoad() {
UltimateSpellAsYouTypes['<%=TextBox1.ClientID%>'].AddEventHandler('keyup', function(evnt) { HandleKeyUp(evnt); });
}

function HandleKeyUp(evnt) {
 //AutoComplete(1,'<%=TextBox1.ClientID%>',evnt);
document.getElementById('<%=TextBox1.ClientID%>').value="This does not work";
alert(document.getElementById('<%=TextBox1.ClientID%>').value)
}
</script> 

The AutoComplete function is commented in the code. To illustrate the problem I change the value of the textbox and display an alert the text in the Textbox1 is correct but the text in the DIV created by UltimateSpell is not.

How can I get the id of the DIV to update the text based on the content of the Textbox?

Thanks.


  
  28 Oct 2007, 3:38 AM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Re: Additonal Java Script with Spell as you type

You can update the content of the SpellAsYouType textbox as follows:

UltimateSpellAsYouTypes['TextBox1'].Restart();

This will update the content based on the content of your original textbox and restart the spell checking process.

You can learn more about the client-side API at http://www.karamasoft.com/UltimateSpell/ClientAPI.htm


  
  28 Oct 2007, 5:11 AM
montoya.juanc is not online. Last active: 11/12/2007 4:13:30 AM montoya.juanc

Top 10 Posts
Joined on 10-28-2007
Posts 5
Re: Additonal Java Script with Spell as you type

The UltimateSpellAsYouTypes['TextBox1'].Restart(); solves part of the problem and my AutoComplete is in some way working now. The autocomplete needs to get the position of the cursor to know where to insert the text, since not always the user will be typing at the end of the textbox.

The problem now is that I do not have the cursor in the textbox. The cursor is in the DIV object and when I read the position of the cursor I always get (-1), I need access to the DIV object in order to get the position of the cursor and use the same position in the textbox.

Please advice.

Thanks


  
  28 Oct 2007, 11:44 AM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Re: Additonal Java Script with Spell as you type
We are not quite sure if we understand what exactly you are trying to achieve. Please clarify how you are getting the cursor position and getting -1 so that we can help you better. Please also clarify why you would need the same position in the textbox since your textbox is already virtually invisible because of the SpellAsYouType. Thanks.
  
  28 Oct 2007, 12:37 PM
montoya.juanc is not online. Last active: 11/12/2007 4:13:30 AM montoya.juanc

Top 10 Posts
Joined on 10-28-2007
Posts 5
Re: Additonal Java Script with Spell as you type
I am using AJAX to read data from a data base. The script that I use is attached to the TEXTBOX. So if the user types "bil", I make a call to the database get a string with the text "Bilateral" and I replace it in the text box. This part works when I am at the end of the text box, and I can get the position of the cursor by calculating the text.length. The problem is that if the user needs to start typing in the middle of some existent text I need the position of the cursor to insert the result at that position.

For example:
 Textbox value : this
 User Types: this bil
 AutoComplete result: this bilateral

 Textbox value : this situation
 User Types: this bil situation
 AutoComplete result: this bilateral situation

In the second case I need to insert bilateral between this and Situation.
In that case I need the posotion of the cursor. I have a function to do that:

function GetCursorPos(objArea){
var i=objArea.value.length+1;
if (objArea.createTextRange){
    theCaret = document.selection.createRange().duplicate();
    while (theCaret.parentElement()==objArea
    && theCaret.move("character",1)==1) --i;
}
    return i==objArea.value.length+1?-1:i;
}

if I pass the object as argument it returns the cursor position, I have been using this for a long time and it works very well if I pass the textbox object as argument. The problem now is that with spell as you type the textbox does not have the cursor and when I get the position I get -1, so I have two options:

First: Use the control created by Spell as you type and work with it.

Second: get the position of the cursor in that "created control" and apply that position to the text box now invisible.

If I know how to get access to that object I can solve my problem but I can not find how to access those objects on top of my textboxes.

Thanks

PS: I know I can use a custom dictionary, but these are medical terms different per doctor and per specialty. Each doctor has different keywords they have been using for years, there is an interface to modify those "macros" and the dictionary will not be as flexible as this approach we already have in place.

  
  29 Oct 2007, 12:32 AM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Re: Additonal Java Script with Spell as you type
We added a new client-side API method GetCurrentRange() to return the current range object inside the SpellAsYouType textbox. This method returns a range object and you can apply your own range methods on this object to move the caret position.

We will release a new build and let you know when it is ready to download. In the meantime, we will send you a patch so that you can try it in your development.

You can call GetCurrentRange method as follows:

var theCaret = UltimateSpellAsYouTypes['TextBox1'].GetCurrentRange();

Please also refer to Internet Explorer documentation to see more about the range object returned by this method.

  
  11 Nov 2007, 3:06 PM
montoya.juanc is not online. Last active: 11/12/2007 4:13:30 AM montoya.juanc

Top 10 Posts
Joined on 10-28-2007
Posts 5
Re: Additonal Java Script with Spell as you type
I am testing your GetCurrentRange() method, and I still have some problems. With the GetCurrentRange() I get the selection range. I tried using GetCurrentRange().parentElement but it does not work. I need to be able to modify the CurrentRange in order to replace the keyword with the content is is pointing to.
 
Lets say I have "bil" and it must be replaced with "Bilateral"

When I type a keyword "bil" and a space, I am checking the keyup event. If it is a space I use GetCurrentRange() and it will give me where to insert the text "Bilateral" but I have no way to delete the keywod "bil". I think the problem is that GetCurrentRange() is returning the selectionRange not the full textRange of the control.

With the full textRange I should be able to find the caret and select the previous word to replace it.

I tried:

var SelectRange = UltimateSpellAsYouTypes['TextBox1'].GetCurrentRange();
var FullRange = SelectRange.parentElement.createTextRange()
alert(FullRange.htmlText);

But it does not work.

To get the range you are returning I do not need to call GetCurrentRange(),

var SelectRange = UltimateSpellAsYouTypes['TextBox1'].GetCurrentRange();

will give me the same result as

var SelectRange = document.selection.createRange()

What I need is a new method GetTextRange() that returns:

WhateverIsYourObject.createTextRange();


Thanks


  
  11 Nov 2007, 9:12 PM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Re: Additonal Java Script with Spell as you type
parentElement is a method (not a property) as can be seen at http://msdn2.microsoft.com/en-us/library/ms536654.aspx

Therefore, you should call it with parantheses as follows:

var FullRange = SelectRange.parentElement().createTextRange();

  
  12 Nov 2007, 3:27 AM
montoya.juanc is not online. Last active: 11/12/2007 4:13:30 AM montoya.juanc

Top 10 Posts
Joined on 10-28-2007
Posts 5
Re: Additonal Java Script with Spell as you type
Thank you very much for your excellent support, everything is working now.
  
 Page 1 of 1 (9 items)
Karamasoft Support Forums » General Discussions » UltimateSpell » Re: Additonal Java Script with Spell as you type

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.