Q. about validating/formatting user input

Jeanne A. E. DeVoto jeanne at runrev.com
Fri Oct 4 01:15:01 CDT 2002


At 5:12 PM -0700 10/3/2002, Alex Rice wrote:
>In Cocoa/ObjC there is this concept of NSFormatter, which both
>validates user input from a text field, and also formats display of the
>content. Is there any similar thing in Rev?
>
>In Rev, what I am thinking about doing is using the keyDown message and
>regex matching to validate the input and allowing or disallowing the
>keystroke that way. However, how can one extent that to entire classes
>or textfields. Seems like it would involve a property and using the
>message path, and I have an idea, but haven't been using rev long
>enough... what's the most elegant way to do this?

One way would be to place a keyDown handler in the stack script, then test
it to see whether the target has a certain custom property set, and do the
formatting if so. A simple example:

  on keyDown theKey -- in stack script
    if the acceptOnlyDigits of the target is true then
      if theKey is not in "0123456789" then
        beep
        exit keyDown
      end if
    end if
    pass keyDown
  end keyDown

Then you set a custom property called "acceptOnlyDigits" for any field in
the stack that you want to set up the behavior for.

--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
Runtime Revolution Limited - The Solution for Software Development
http://www.runrev.com/





More information about the use-livecode mailing list