Page 1 of 1

Limiting Field Length

Posted: Tue Oct 06, 2009 3:26 pm
by chris9610
I am looking for a solution to this issue. I can limit an input field to a determined length but this also changes a part of the behavior.

Code: Select all

on keydown
   if the length of me >= 6 then focus me
   else pass keydown
end keydown
This works fine until I use it while editing and existing field contents. When this field contents is full and hilighted then you must press the BACKSPACE KEY or the DELETE KEY to change the contents.

If the field is not full then the behavior is normal and any key will erase the existing contents.

Is there a way to make it behave the same even if the field length is full?

Re: Limiting Field Length

Posted: Tue Oct 06, 2009 6:13 pm
by sturgis
This should work. Check for a selection first, if anything is selected, pass the key, else check length and determine if its at max size, if not pass the key, else focus me.

Code: Select all

on keyDown theKey
   if the length of the selectedText of me > 0 then 
      pass keyDown
   else if the length of me >= 6 then
     focus me
   else
      pass keyDown
   end if
end keyDown
chris9610 wrote:I am looking for a solution to this issue. I can limit an input field to a determined length but this also changes a part of the behavior.

Code: Select all

on keydown
   if the length of me >= 6 then focus me
   else pass keydown
end keydown
This works fine until I use it while editing and existing field contents. When this field contents is full and hilighted then you must press the BACKSPACE KEY or the DELETE KEY to change the contents.

If the field is not full then the behavior is normal and any key will erase the existing contents.

Is there a way to make it behave the same even if the field length is full?

Posted: Tue Oct 06, 2009 6:21 pm
by chris9610
sturgis:

Many thanks, works as expected now.

Some things are so simple when you know what you are doing.