Search code examples
angularjsangular-formly

Automatically add hyphens to number field


My form has a few fields that need filters. For instance, there is a SSN field.

I am currently checking that the user has entered in the correct pattern (and displaying validation that it is wrong if need be). However, this requires the user to enter the hyphens themselves. What I would like to do is automatically adds the hyphens as the user enters their number.

How would I accomplish something like this? I already have a custom type that I created for the SSN field. Maybe in the controller of this custom field?


Solution

  • I just realized that Kent already has an example of how to do this using uiMask module:

    http://angular-formly.com/#!/example/integrations/ui-mask