jaridmargolin / formatter.js

Format html inputs to match a specified pattern
http://firstopinion.github.io/formatter.js
2.48k stars 235 forks source link

Trigger Formatter to update a field? #80

Open Enchiridion opened 9 years ago

Enchiridion commented 9 years ago

Hi, How can I trigger formatter to update the contents of a field programmatically?

I'm asking because I'm using formatter to display a phone number as (xxx) xxx-xxxx, however it's stored in the database as xxxxxxxxxx. So after a form is saved and reloaded, the value in the field displays as xxxxxxxxxx. I want to tell formatter to immediately update the field so it looks like (xxx) xxx-xxxx again.

The only public function that I could get to trigger an update was .resetPattern(), but it fails when I pass it an array of patterns. Haven't had any luck with the 'private' methods, and I'd rather not use those if possible.

I'm using v0.1.5.

Thanks!

sciotta commented 9 years ago

+1

Jeff-P commented 8 years ago

after your pattern you need to add'persistent': true and when you load data automatically on the input it will auto format