The current data linking proposal also supports a feature
called converters. A converter enables you to easily convert the value of a
property during data linking.
For example, imagine that you want to represent phone
numbers in a standard way with the “contact” object phone property. In
particular, you don’t want to include special characters such as ()- in the
phone number - instead you only want digits and nothing else. In that case, you
can wire-up a converter to convert the value of an INPUT element into this format
using the code below:
Notice above how a converter function is being passed to the
linkFrom() method used to link the phone property of the “contact” object with
the value of the phone INPUT element. This convertor function strips any
non-numeric characters from the INPUT element before updating the phone
property. Now, if you enter the phone number (206) 555-9999 into the
phone input field then the value 2065559999 is assigned to the phone property
of the contact object:
You can also use a converter in the opposite direction also.
For example, you can apply a standard phone format string when displaying a
phone number from a phone property.