Cursor position in text box

Done!

Some characters like *+() are causing an unexpected quantifer error. Is there another way, other then using the key pressed to exclude the look up or using reg-x to not allow them, to avoid the error? I’d like to allow all characters if possible.

Thanks in advance.

ah yes, that would create a problem, as the ‘+’ is a quantifier in regular expressions meaning 1 or more. However, there is a fix! Change this line


var regex = new RegExp( "^" + sVal, "i" );

to


var regex = new RegExp( "^" + sVal.toPattern(), "i" );

Now, we need to add the toPattern method – just insert this into the the <script> block in the HTC


String.prototype.toPattern = function()
{
	return this.replace( /([\\.\\*\\+\\{\\}\\(\\)\\<\\>\\^\\$\\\\])/g, "\\\\$1" );
}

Although I haven’t tested this specific application, I used the toPattern method alot for building regexs from strings, so I suspect this should work just fine.

Looks like toPattern() is a Java method. Looked on google and MSDN only found ref to Java. I was starting to think I need to go back to school. But then on a hunch based on your code I changed…

This : var sVal = element.value

To This : var sVal = element.value.replace( /([\.\*\+\{\}\(\)\<\>\^\$\\])/g, "[\\$1](file://\$1)" );

And it seems to be working!

Well, toPattern() may very well be a Java method, but it’s not an inherent (host) method in ECMAscript (that’s javascript to you). Fortunately, javacript is a prototype-based OO scripting langauge – that’s why I prototyped the toPattern method onto String objects

String.prototype.toPattern = function()
{
	return this.replace( /([\\.\\*\\+\\{\\}\\(\\)\\<\\>\\^\\$\\\\])/g, "\\\\$1" );
}

I though I made it reasonably clear that you’d need to include this

Oh well, what you have done is essentially the same thing, I just like to use custom methods for the sake of reusability.

I did include it, I’ll have to take a look at what I did in the AM.

Thanks

Ok this is sad, I put the function inside the
keyHandler() function! I set it up the right way and it worked.

:smiley: :tup:

Beetle, this is something you helped me with in May. I have resolved most issues with the app but ran into this one that I have not been able to make sense out of. I made a test page so you can see the error. Will still need the component above to make it work.

If you’re out there please let me know what you think.

Thanks

<STYLE TYPE=“text/css”>
input.autoFill {
behavior:url(auto_fill.htc)
}
</STYLE>

<script language=“JavaScript”>
var vals = [‘TEst Project’,‘Developer Assist’,‘Time Management’,‘Developer Assist’,‘email’,‘Warranty’,‘Meeting’]
</script>

[color=blue][b]<FORM>
Running into the following problem when making a change to the selected value…

The textbox below uses the autoFill behavior. If the value is in the array [‘TEst Project’,‘Developer Assist’,‘Time Management’,‘Developer Assist’,‘email’,‘Warranty’,‘Meeting’]
(i.e. TEst Project) it comes up fine. The error occurs when you change the first letter
i.e. once “TEst project” comes up use the mouse to highlight the “T” change it to lower case this
is where you will get the “invalid argument” error. I tracked it down to where the
component calls this statement [found = tr.findText( element.value.replace( regex, “” ), -1 );]
<br>
I actually would like to stop the update process if the user goes back and changes something, like making the “T” lower case.
<br>
Has autoFill behavior : <INPUT class=“autoFill” autocomplete=“off” type=“Text” name=“txtSrProj_8” id=“txtSrProj_8” maxlength=“20” size=“15” value=“”>
<BR>[/b][/color]
I have tried several hacks the result was no error but the “t” went back to upper case. Would be nice if once the user goes back I can stop the updates.
</FORM>

I reposted this under http://www.sitepointforums.com/showthread.php?threadid=119424. Just thought this was to way long.
Thanks