braintree / restricted-input

Restrict <input>s to certain valid characters (e.g. formatting phone or card numbers)
https://braintree.github.io/restricted-input/
MIT License
68 stars 25 forks source link

Format at initialization? #51

Closed Scrum closed 5 years ago

Scrum commented 5 years ago

What is the sacred meaning not to format at initialization?

crookedneighbor commented 5 years ago

Can you explain a little more about what you are asking?

Scrum commented 5 years ago

Yep :)

If i have input element with value

<input value="41111111">

and initialize restricted-input

const formattedCreditCardInput = new RestrictedInput({
      element,
      pattern: '{{9999}} {{9999}}'
    });

The value in the input is not formatted. A basic strategy was chosen in which the

function BaseStrategy(options) {
  this.isFormatted = false;
  ...
}

and there is no explicit trigger for the value to be formatted

Scrum commented 5 years ago

I created a demo for a credit-card-gaps-pattern that creates a pattern for restricted-input in which you can watch as I clearly trigger call setPattern to initialize formatting

crookedneighbor commented 5 years ago

Having it set the pattern on initialization seems reasonable. Would you like to open a PR?

Scrum commented 5 years ago

@crookedneighbor Would you like to open a PR? Yep, in process.

Would you be interested if I transferred to your org credit-card-gaps-pattern ?

Scrum commented 5 years ago

@crookedneighbor

Would you like to open a PR?

success #52

crookedneighbor commented 5 years ago

No, we do not wish to maintain credit-card-gaps-pattern at this time.

Scrum commented 5 years ago

not problem :)

crookedneighbor commented 5 years ago

This is out with v2.0.0