GithubHelp home page GithubHelp logo

jaridmargolin / formatter.js Goto Github PK

View Code? Open in Web Editor NEW
2.5K 2.5K 300.0 996 KB

Format html inputs to match a specified pattern

Home Page: http://firstopinion.github.io/formatter.js

JavaScript 95.40% CSS 4.60%

formatter.js's People

Contributors

brianpeiris avatar bryanjswift avatar fdaugan avatar jaridmargolin avatar jarofghosts avatar mickeyreiss avatar muffinresearch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formatter.js's Issues

Dot (.) Issue

When i use my own regex

$.fn.formatter.addInptType('D', /[A-Za-z0-9.]/);

$('#web').formatter({
'pattern': 'http://www.{{DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}}',
'persistent': true
});

Like this

When i start to type github.com for example it goes back right after c

In this case when i type directly github it becomes like this

github.omc

Can't solve this issue thank you

Placeholder

It would be nice to have a third option for placeholder text.

Ex:
new Formatter(birthDateInput, {
'pattern': '{{99/99/9999}}',
'persistent': true
'placeholder': 'MM/DD/YYYY'
});

Wrong minified versions

The unminified version of formatter.js are fine, but the minified ones are using "require" - both the jquery and non-jquery versions are affected. The un-minified versions work just fine after getting minified/uglified.

Problem with telephone number formating.

So i have this number in my input value 608291461.
Also i have formatter setup to .formatter({ 'pattern': '+48 {{999}} {{999}} {{999}}', 'persistent': true }). After transformation by formatter in my input 8 number from 608 disappears and result is only a +48 602 914 64.

Add IE7 support

On IE7, no Javascript error, and the typed text is not visible.
Even the initialized text by html value is not visible.
Works well on IE8.

Tested on master and the 5 days ago masters's version.
jquery version : 1.8.3

Foreign language accents still appearing

When foreign languages are enabled for the keyboard, the accents associated with that language can still be triggered. Formatter ignores them once a number is struck, but they still show when typing.

Opera Mobile doubles every char on input

I have a classic pattern for credit cards
pattern: '{{9999}} {{9999}} {{9999}} {{9999}} {{99}}'
When I try to enter the number in Opera Mobile, every digit is entered twice, so I have to delete an extra char.

add hover

hola, creo que debería haber una la posibilitad de agregarle un hover de los espacios

Incorrect cursor position with multiple patterns

I want to format phone number on input.
If I use single 'pattern' option everything is fine.
But if I use something like this:
'patterns': [
{ '^\d{5}$': '{{9}} {{99}} {{99}}' },
{ '^\d{6}$': '{{99}} {{99}} {{99}}' },
{ '^\d{7}$': '{{999}} {{99}} {{99}}' },
{ '': '{{*******************}}' }
],
'persistent': false
after 5th digit my cursor is not at the end but between 4th and 5th symbol.

Color separator

Is there a way to target the pattern separator in order to change its color?

Allow Caps Enforcement

Would it be possible to implement forced capitalization in patterns? Specifying 'A' instead of 'a' for auto capitalization, for example?

use jQuery instead of $

Hi there,

in the jQuery version you should use "jQuery" instead of its short version "$". the short version could be overwritten by other libraries.

Thanks,

Jakob

In Mozilla arrow keys trigger keypress

In Mozilla, arrow keys trigger the 'keypress' event. The keypress handler assumes it is a character keystroke and calls preventDefault, causing the key to not be handled correctly.

Formatter reset or re-instantiate request

There's a special code in jQuery wrapper that prevents multiple instances of Formatter to be created which is good. The issue come when you seriously need to change pattern on the go. Typical example is credit cards one. Master Card, Visa and Discover all good with 4 groups of 4 digits. 16 total. American Express instead has 3 groups with 4, 6 and 5 digits. 15 total. Which card user types in you can get by first digit - it's 3 for Amex. Of course you can delay instantiation until user types first digit but what if he changes his mind later?

Android Webview Work Wrong

when i use formatter in android webview, it is formatter is {{999}} {{9999}} {{9999}}, when i input to 4rd number, the inptSel go to the error position, can you fix it ?

Comma missed in sample of main documentation

$('#credit-input').formatter({
  'pattern': '{{999}}-{{999}}-{{999}}-{{9999}}'
  'persistent': true
});

Should be read :

$('#credit-input').formatter({
  'pattern': '{{999}}-{{999}}-{{999}}-{{9999}}',
  'persistent': true
});

Add support for currency formats

Do you have any plans to add support for formatting inputs for currency values (e.g. – $#,###.##)?

Maybe something along the lines of this...

var formatted = new Formatter(document.getElementById('input-currency'), {
  'pattern' : '${{9}},{{999}}.{{99}}'
});

Android Phones

Thanks for your work.

On Android devices were you have a phone number pattern ,the number is typed out of order. When you hit a number it goes in front of the previous number.

I am using this pattern:

'pattern': '({{999}}) {{999}}-{{9999}}'

If I use this pattern:

'pattern': '{{9999999999}}'

It works.

Android Version: 2.2.2
Android Version: 4.0.3

Several keys' behavior overridden by the library causing usability issues

The formatting options are great... but as a user it bugs me that the usability of the text fields have been compromised as a result of the library.

For example the arrow keys (left, right) no longer navigate within the text field should the user want to correct a typo.

The delete key (on a PC) should "erase" characters to the right of the cursor/caret yet currently erases characters to the left like a backspace key.

The shift key has been disabled so manually selecting multiple characters to delete/type over is not possible.

The Home key does not take the user's cursor/caret to the beginning of the field/line... nor does the End key take the user to the end of the field/line.

requiring as a CommonJS module doesn't work

It may be related to how you convert formatter.js to CommonJS, but all of the require statements for internal modules are not using relative paths.

In the main file (dist/common/formatter.js:8-10) the require statements should be like this:

var patternMatcher = require('./pattern-matcher');
var inptSel = require('./inpt-sel');
var utils = require('./utils');

Notice the relative paths being used. The compiled CommonJS files should all be using relative paths for in-module requires 😄

Change event suppressed

I tried to bind an event handler to the "change" event and it works fine for inputs where I don't use formatter.js and it catches no change event (doesn't work) when I use it on inputs where I applied formatter.js.

So using this http://api.jquery.com/change/ does not work. And I'm guessing trying to catch other events won't work either. I saw an issue where users could not catch the "input" event for example (which, just to clarify, is not the same thing as the change event).

Special keys

The special keys list should be extended, it is not possible to go to the next form field by pressing tab, or submit the form by pressing enter. One more possible extention is also to support F5.

utils.isSpecialKey = function (k) {
  var codes = {
    '9' : 'tab',
    '13': 'enter',
    '35': 'end',
    '36': 'home',
    '37': 'leftarrow',
    '38': 'uparrow',
    '39': 'rightarrow',
    '40': 'downarrow',
    '116': 'F5',
  };
  // If del or special key
  return codes[k];
};

cheers

The input element's type ('number') does not support selection.

Formatter fails with input number on Chrome Canary v34.0.1798.0

<input type='number' class='myNumber' placeholder='1' min='0' max='50' step='1'>
$('input.myNumber').formatter({ pattern: '{{99}}' });

with an error message visible in the console:

Uncaught InvalidStateError: Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.

Any text or number can be typed it.

Only 1 'persistent': true field is allowed on Internet Explorer

I have a form as below:

  • field1 : text
  • field2: formatted text, with 'persistent': true
  • field3: formatted text, with 'persistent': true
  • field4: text

When the form loads, field3 has the focus and I can only move the focus to field2. When trying to write on field1 or field4, the focus moves back to field3. It's only possible to write on field1 or field4 after field2 and field3 are filled.

This is fixed by removing the 'persistent': true of one of the formatted fields, field2 or field3.

I am using v0.1.5 with IE 11.

Optional characters

Is there any option to use repetition, e.g. {{99?}} or {{9{1,2}}}? This would allow to specify variable format like optional characters that may or may not be specified.

Plain formatting

can I use this outside of a node?

– goal:

var formatted = new Formatter('123123123', '({999}) - ({999}, {999})'); // (123) - (123, 123)

There's any way to reach this?
Thanks.

Format time field (HH:MM)

How can I mask input to accept only 24-hour format? I've tried something like:
new Formatter(timeElems[i], {
'pattern': '{{99}}:{{99}}',
'persistent': false,
'patterns':[
{ '^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$': 'time: {{*****}}' }
]
});

but it doesn't work at all.

Enabling/disabling formatter

Currently it's not possible to unbind all events attached by formatter and disable it completely.

Such a feature would be really useful - just look at the issue #29. If it would be possible to disable the formatter we could still dynamically change the input type to "number" for mobile users.

jQuery input event suppressed

Enabling formatter for example in an input element prevents to fire jQuery input event on that particular element. I consider this a bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.