jaridmargolin / formatter.js

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

Add multi-pattern support. #38

Closed braintreeps closed 10 years ago

braintreeps commented 10 years ago

Hi there!

We wanted to use this library to add validations on a credit card form. In our case, the desired behavior was to change the formatting patterns based on the credit card type and whether or not the user enters an expiration date starting with a 0, 1, or other number.

In order to accomplish this, we augmented formatter.js to accept a set of patterns, in addition to the single pattern it previously accepted. Basically, you provide a set of regex patterns and corresponding format patterns. The library then dynamically applies a pattern based on the input element's value each time it changes.

These changes are fully backwards compatible with one exception. myFormatter.opts.pattern is no longer accessible as the pattern now is saved as a patternMatcher, rather than a pattern string.

The changes to README and tests should give you a more precise outline of the new behavior.

Cheers! Mickey

jaridmargolin commented 10 years ago

Looks awesome on first review. Much appreciated!

mickeyreiss commented 10 years ago

Cool, no problem. BTW, we have a few more bug fixes and enhancements underway. So if you'd prefer to wait a few more days (mid next week?) to merge/release that's fine with us!

mickeyreiss commented 10 years ago

@jaridmargolin This is good to go! Thanks.

jaridmargolin commented 10 years ago

Really solid work.

jaridmargolin commented 10 years ago

Will bump the version so this is accessible via various package mangers.

burnto commented 10 years ago

@mickeyreiss nice work.

mickeyreiss commented 10 years ago

@jaridmargolin Can you @reply me when release is complete, so I can move our internal stuff off of our fork@master, onto your new version.

jaridmargolin commented 10 years ago

@mickeyreiss - v0.1.1 has been released.

jaridmargolin commented 10 years ago

@mickeyreiss - I have actually reverted some of the work you completed. Specifically the last PR titled, "Fix trailing format char bugs for persistent false."

Reasoning: It was a breaking change. Unfortunately at the time of your push, there were no tests for this particular case. I have implemented here: https://github.com/firstopinion/formatter.js/blob/master/test/formatter.js#L266. I found the above a more pressing issue than your preference on how trailing characters should be deleted. I would be open to reconsidering your preference, if you would like to submit a new PR that passes with the additionally added tests.

Thanks.