Giter VIP home page Giter VIP logo

ember-cli-maskedinput's Introduction

Build Status Ember Observer Score npm version

Ember masked-input

This addon provides a <MaskedInput> Glimmer component that applies input masking based on inputmask-core.

There are no dependencies on jQuery plugins so this addon is a more lightweight and faster alternative to other input masking addons. It's based on the solid inputmask-core library and adapted from its React implementation MaskedInput.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v14 or above

Installation

ember install ember-cli-maskedinput

Usage

Basic usage

Pass the value to display and a on-change function as args to the MaskedInput component:

<MaskedInput @mask='A1111' @value={{this.myValue}} @on-change={{fn this.updateMyValue}} />
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";

export default class MyComponent extends Component {
  @tracked myValue = 0;

  @action
  updateMyValue(e) {
    this.myValue = e.target.value;
  }
}

Date pattern

<MaskedInput @mask='11/11/1111' @value={{this.myValue}} @on-change={{fn this.updateMyValue}} />

Credit card pattern

<MaskedInput @mask='1111 1111 1111 1111' @value={{this.myValue}} @on-change={{fn this.updateMyValue}} />

Time pattern with validation

Uses plain HTML5 validation by setting HTML attributes:

<MaskedInput @mask='11:11:11' required pattern='[0-9]{2}:[0-9]{2}:[0-9]{2}' title='Time value with format HH:MM:SS' />

Reference

mask

A pattern consisting of 1 (number), a (letter), A (letter forced upper case), * (alphanumeric), # (alphanumeric forced upper case) or any other character for static parts of the mask. Use backslashes to escape format characters.

See inputmask-core docs for more information.

formatCharacters

An object defining additional format characters, see inputmask-core docs for more information.

placeholderChar

The character which is used to fill in editable positions that have no input. Defaults to _; must be a single character.

on-change

An optional function to handle change events.

License

MIT Licensed

ember-cli-maskedinput's People

Contributors

bracke avatar czterystaczwarty avatar ember-tomster avatar fpalluel avatar hlubek avatar khornberg avatar krasnoukhov avatar mike-north avatar remkoboschker avatar ryanponce 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

Watchers

 avatar  avatar  avatar

ember-cli-maskedinput's Issues

Focus gets trapped in masked input

Hello,
when navigating through form inputs, using the tab key, the focus gets 'trapped' in the masked input (once entered, you cannot get out by using the keyboard, you must use the mouse).
I had to patch masked-input.js, line 144, by changing this :

if (e.metaKey || e.altKey || e.ctrlKey || e.keyCode === 13) {
  return;
}

to this :

if (e.metaKey || e.altKey || e.ctrlKey || e.keyCode === 13 || e.keyCode === 9) {
  return;
}

As a side note, I'm successfully using your component with ember-bootstrap, including validation feedback, with this simple lines :

{{#bs-form-element property="myDate" as |value id validationState|}}
  {{masked-input mask='11-11-1111' classNames='form-control' value=value }}
{{/bs-form-element}}

Thank you very much for this lightweight alternative to JQuery's libraries !

Android

It doesn't appear to work on Android.

Tests don't pass in ember 2.8.0-beta.1

From digging a little, seems like the synthesized keyboard events in a test or two aren't making it to the component. I'll do a git bisect to see what change to the framework introduced a problem

Component conflicting with Validations

Hello,

first of all thank you for putting this up. I have two feature requests to make amounts flexible, just like in regex. Also I would say it is rather bad practice to actually put underscores into the property.

Let me explain my use case:

I'm formatting Swiss license plate number which has to meet following regex:
/^[A-Z]{2}\s\d{1,6}$/,

thus, I'm using ember-cp-validations to validate it with a regex.

Now adding the input mask plugin with mask AA 111111 results in an invalid property since your plugin actually writes underscores into the model for open fields.

Ergo: unless I fill up all 6 numbers, i get these underscores in my ember data property which the validator will not like at all.

First I thought I might just need to change the regex to this
regex: /^[A-Z]{2}\s[\d_]{1,6}$/,

then however I found out that the underscores are actually not removed from the property and are even going to be persisted like that...

For now i will have to put up my own solution, but it's an idea that would make your plugin much more robust and usable.

Cheers
Daniel

Does not react to change of value

Hi

If the value passed to the component changes, the component does not react/change.

Adding value to the computed decorator of the inputMask getter fixes the problem.

@computed('args.{value,mask,formatCharacters,placeholderChar}')

Kind regards
Bent Bracke

Get access to the raw value

Hi there,

I noticed the component returns a formatted value, is there a way to get access to the raw value instead?

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.