Add multi-pattern support. #38

Merged
merged 3 commits into from Mar 20, 2014

Projects

None yet

4 participants

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

Owner

Looks awesome on first review. Much appreciated!

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!

@jaridmargolin This is good to go! Thanks.

Owner

Really solid work.

@jaridmargolin jaridmargolin merged commit 4b94b66 into firstopinion:master Mar 20, 2014

1 check passed

default The Travis CI build passed
Details
Owner

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

burnto commented Mar 20, 2014

@mickeyreiss nice work.

@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.

Owner

@mickeyreiss - v0.1.1 has been released.

Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment