Glimmr Form Fields

version 1/101201 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Input interpretation

    If we wish, we can specify how GFF should interpret a given field input by using the "input interpretation" rules. This rulebook is run on a field whenever that field gains or loses focus, and is an object based rulebook, so that we can write rules of the sort:

        Input interpretation: (applies to any field)
        Input interpretation for a g-element: (applies to any field)
        Input interpretation for an input field: (applies only to the "input field" kind)
        Input interpretation for my input field: (applies to a single named field)
        Input interpretation for my input field when keypress-code terminates input:

    The last preamble will function only when a control key was pressed to terminate input (effectively, this tells us that the player did not click to abandon input, but instead actively pressed a key, such as the Enter or Escape key, to complete).

    The input interpretation rules can be used to clean up or otherwise alter the player's input before our game does anything with it. The input interpretation rules should either redefine the text-string of the field's input-stream, or set some other variable based on the contents of the string. The graphics window will be refreshed after the input interpretation rulebook runs, so that any change made to the text-string from within will be reflected to the player, so keep that in mind when using it. If you want to keep your changes to the text-string secret from the player, make any changes to the text-string after the field input loop is completely finished.

    Here's how to write a rule that would remove all punctuation (though if you don't want any punctuation, it may be better to simply disallow it with the standard input filter):

        Input interpretation for a g-element (called the field):
            replace the regular expression "\p" in the text-string of the input-stream of the field with "".

    GFF provides a rule that fires by default for all fields, the "trim graceless spaces rule", which trims leading and trailing spaces from the input.
            
    The only other interpretation rule provided by GFF, the "field to number conversion rule," converts the text-string into another type. This rule runs only when an input field has been declared to be "numerical," and it reinterprets the indexed text input as a number, the "associated value" of the field element (see the Numeric Input Fields section below).