20130621 (Friday, 21 June 2013)

Input masks for text fields

Flavio asked:

In Django I used a library with JQuery for input masks for fields like phone number etc. I think a more elegant solution could be the mask already be implicit in the field type, and/or a field attribute to the mask string, which would be handled by the framework. I would like to know how to proceed to use input masks with Lino.

Added a new class dd.CharField which extends the default Django CharField. See the docstring and the following external references:

Usage example in the new input_mask_test field of The Lino Polls tutorial:

input_mask_test = dd.CharField("Question text",
    help_text="""This field is here to play with the
    CharField parameters regex, mask_re and strip_chars_re.
    By default it accepts all letters except Z.
    #~ regex='/^[a-yA-Y]*$/')
    #~ strip_chars_re='/^[a-yA-Y]*$/')

Since the public tutorial site is read-only you can see the effect only when running it locally after having modifed anonymous_user_type to ‘900’ in /docs/tutorials/polls/mysite/settings.py.