Giter Club home page Giter Club logo

ngx-digit-only's Introduction

Angular DigitOnly Directive and Mask Directive

Build Status npm

Medium Article: Digit Only Directive in Angular

  • input digitOnly directive

    An Angular directive only allows [0-9] in the input box when typing, pasting or drag/dropping. This directive handles both Windows keyboard and Mac keyboard. This directive works with input type="text", not input type="number".

  • input mask directive

    This directive checks the input pattern attribute if set.

CHANGELOG

  • v3.2.0(v2.4.0): digitOnly directive now supports disabling paste events (merges a pull request #57, fixes #56).

  • v3.1.0(v2.3.0): digitOnly directive now supports negative values (merges a pull request #49).

  • v3.0.0: a release on par with Angular 12. For projects in Angular v10 or v11, please use v2 of this library.

  • v2.2.3: fix an issue (#50) in the mask directive: support dynamic pattern attribute binding.

  • v2.2.2: fix an issue (#28) to prevent dead keys in the digitOnly directive.

  • v2.2.1: digitOnly directive now dispatches an input event when paste in Firefox.

  • v2.2.0: fix an issue (#35): for better international support, both mask and digitOnly directives now also check the code attribute in KeyboardEvent.

  • v2.1.0(v1.9.0): fix an issue (#39) when typing decimal numbers for the digitOnly directive

  • v2.0.0: add tslib v2.0 in the dependency, which is required by TypeScript 3.9 (as of Angular 10).

  • v1.8.0: fix an issue (#38) when pasting in IE and Edge for the digitOnly directive

  • v1.7.0: the digitOnly directive allows model binding to min, max, and pattern properties.

    • See demo page for examples.
  • v1.6.0: the mask directive is added to this library.

    • See an example below about an input allows ##-####.
  • v1.5.0: this directive checks the input pattern attribute if set.

    • See an example below about an input only allows decimal numbers with precision of 2.
  • v1.3.0: this directive accepts an attribute for the separator for decimal numbers.

    • By default, the separator is a .. You can set it to comma when needed.
  • v1.1.0: this directive accepts an attribute which indicates if the input number allows a decimal point.


Installation

npm i @uiowa/digit-only

Usage

// in your Angular module
import { DigitOnlyModule } from '@uiowa/digit-only';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserModule,
    DigitOnlyModule
  ],
  ...
})
export class YourModule { }
// in your component.html
<input type="text" digitOnly />

// pull out the numeric keypad in mobile devices and tablets
<input
  type="text"
  name="zipcode"
  id="zipcode"
  placeholder="00000"
  maxlength="5"
  inputmode="numeric"
  pattern="[0-9]*"
  digitOnly
/>

// turn off browser autocomplete
<input ... autocomplete="off" />

// allows decimal input
<input
  id="decimal-number"
  type="text"
  digitOnly
  decimal="true"
  placeholder="000"
/>

// allows to set decimal separator
<label for="digit-only-decimal-comma">
  Digit Only input box that allows a <i>decimal point</i> using
  <strong>a comma as the separator</strong>
</label>
<input
  id="digit-only-decimal-comma"
  type="text"
  digitOnly
  decimal="true"
  decimalSeparator=","
  placeholder="0,00"
  pattern="[0-9]+([,][0-9]+)?"
/>

// Digit Only input only allows two decimal places
<input
  id="currency"
  type="text"
  name="currency"
  inputmode="numeric"
  pattern="^\d+(\.\d{1,2})?$"
  placeholder="0.00"
  digitOnly
  decimal="true"
/>

mask directive usage

// input masked with pattern attribute: <code>##-####</code>
<input
  id="org-dept"
  type="text"
  pattern="^(\d{0,2}|\d{2}-\d{0,4})$"
  name="org-dept"
  title="org-dept"
  placeholder="00-0000"
  mask
/>

ngx-digit-only's People

Contributors

billn6 avatar changhuixu avatar dependabot[bot] avatar engfelix avatar krzysztof-zych avatar loicgasser avatar meigyoku-thmn avatar sauruz avatar sonicsuew avatar tonivj5 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

ngx-digit-only's Issues

Allowing any character after press dead key

Hello, congratulations and thank you for the good work so far. 😉

I found a small bug when typing in a very specific scenario and I would like to share it with you.

The problem:

When I press any Dead Key like '~', '^' or '´' and then press any other key this value is allowed

Browser:

Chrome 80.0.3987.163

Image:

image

Add support for decimal places

Hi,

We'd like to have support for allowing numbers like '123.45' and to be able to limit the number of decimal places to 2 or let's say 4.

This in essence requires to know the whole value of the input to do the validation. Do you have any idea what would be the best way to pull that one off?

I can get the value from the native input, but that is lacking the character(s) to be added, and the hard part is to know where the cursor is. (So that we could construct the resulting value of the input if we let the event continue.)

Thank you for the superb library, it is doing exactly what it says! (And we'd like it to do more :))

How to handle min and max values

Is it possible to handle min and max values for example if we set the min value as 1 and max value as 10. If the user types 0 then is it possible to change the value from 0 to 1.Likewise for the max values

Allow for padding on mask

Currently, the pattern and mask seem to be very rigid...

It would be nice to define something like this:

What this should do (assuming my regex is correct) is allow for inputs of the following:
3/25
1/15
02/01
03/23

For some reason, most of these do NOT work.

02/01 - works
03/23 - works

Trying to type 3/25 yields -> 32/5
Trying to type 1/15 yields -> 11/5

Is there a way when the user types 3/ to force it to recognize that the user really means 03/?

Paste not working in IE or Edge

When I try to Paste in IE I get an error because the clipboardData is not available on the event.

I can also see that the pasteData method uses the HTMLInputElement setRangeText method which is not supported in IE or Edge.

add a new input parameter to control the decimal precision

Propose:

This directive will accept an optional input parameter: decimalPrecision.

  • The parameter decimalPrecision is a number. Default is 0, which will not take effect. If the value is a number other than 0, then it must be a positive integer. Otherwise, if negative, assign a value of 0; if not integer, assign its floor integer.
  • The parameter decimalPrecision will take effect only when decimal is true.
  • If the number of digits equals the decimalPrecision, then prevent typing/pasting/dropping.

Allow special chars by choice

Thanks for the great and easy to use plugin but I am missing some key feature. How can I accomplish to allow some special chars like + or - keys? I tried allowing them via regex ^[\d +-]+$ in the pattern attribute, but this doesn't seem to work. Any tips?

ng build --prod is failing

this command works fine:
ng serve

but when
ng build --prod

it's giving errors:

ERROR in ./node_modules/@uiowa/digit-only/fesm5/uiowa-digit-only.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'kind' of undefined

this is my package.json

{
  "name": "test",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:prod": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "1.0.0-beta.7",
    "@angular/animations": "8.1.2",
    "@angular/cdk": "^8.1.1",
    "@angular/common": "8.1.2",
    "@angular/compiler": "8.1.2",
    "@angular/core": "8.1.2",
    "@angular/flex-layout": "8.0.0-beta.26",
    "@angular/forms": "8.1.2",
    "@angular/material": "^8.1.1",
    "@angular/material-moment-adapter": "8.1.1",
    "@angular/platform-browser": "8.1.2",
    "@angular/platform-browser-dynamic": "8.1.2",
    "@angular/router": "8.1.2",
    "@aspnet/signalr": "^1.1.4",
    "@ng-idle/core": "^8.0.0-beta.4",
    "@ng-idle/keepalive": "^8.0.0-beta.4",
    "@ngx-translate/core": "11.0.1",
    "@types/prismjs": "1.16.0",
    "@uiowa/digit-only": "^1.9.0",
    "ag-grid-angular": "^21.0.1",
    "ag-grid-community": "^21.0.1",
    "angular-in-memory-web-api": "0.8.0",
    "classlist.js": "1.1.20150312",
    "file-saver": "^2.0.2",
    "hammerjs": "2.0.8",
    "lodash": "4.17.15",
    "moment": "^2.24.0",
    "ngx-cookie-service": "2.2.0",
    "ngx-currency": "^2.5.2",
    "oidc-client": "^1.8.2",
    "perfect-scrollbar": "1.4.0",
    "prismjs": "1.16.0",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.5.2",
    "tslib": "^1.14.1",
    "web-animations-js": "2.3.2",
    "xlsx": "^0.14.3",
    "zone.js": "0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.800.0",
    "@angular/cli": "~8.0.4",
    "@angular/compiler-cli": "~8.0.1",
    "@angular/language-service": "~8.0.1",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  }
}

MaskDirective not supporting dynamic pattern attribute binding

I am trying to build a component that allows passing in a dynamic pattern string value.

my.component.html:

<input [id]="id" 
       type="text"
       ...
       mask
       [pattern]="pattern"
       [placeholder]="placeholder">

It works when I use 'pattern="^somePattern$"', but not when using dynamic attribute binding.
This is because the variable 'this.regex' is set in the constructor, where the pattern is still not present.

I think this can be resolved by setting the variable in an appropriate lifecycle hook.

Version: 2.2.2

keyCode is deprecated

Hi Guys,

Just a heads-up.
Our TypeScript linter throws an error that keyCode is deprecated so, we refactored the code to:

private navigationKeys = ['Backspace', 'Delete', 'Tab', 'Escape', 'Enter',
            'Home', 'End', 'ArrowLeft', 'ArrowRight', 'Clear', 'Copy', 'Paste'];
    inputElement: HTMLElement;
    constructor(public el: ElementRef) {
        this.inputElement = el.nativeElement;
    }

    @HostListener('keydown', ['$event'])
    onKeyDown(e: KeyboardEvent) {
        if (
            (this.navigationKeys.indexOf(e.key) > -1) || // Allow: navigation keys: backspace, delete, arrows etc.
            (e.key === 'a' && e.ctrlKey === true) || // Allow: Ctrl+A
            (e.key === 'c' && e.ctrlKey === true) || // Allow: Ctrl+C
            (e.key === 'v' && e.ctrlKey === true) || // Allow: Ctrl+V
            (e.key === 'x' && e.ctrlKey === true) || // Allow: Ctrl+X
            (e.key === 'a' && e.metaKey === true) || // Allow: Cmd+A (Mac)
            (e.key === 'c' && e.metaKey === true) || // Allow: Cmd+C (Mac)
            (e.key === 'v' && e.metaKey === true) || // Allow: Cmd+V (Mac)
            (e.key === 'x' && e.metaKey === true)    // Allow: Cmd+X (Mac)
        ) {
            // let it happen, don't do anything
            return;
        }

        // Ensure that it is a number and stop the keypress
        if (isNaN(Number(e.key))) {
            e.preventDefault();
        }

You can see a fat warning on this page too: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
I'd suggest to implement it here as well.

v3.0.0 allows non numeric inputs

I recently upgraded to angular 12.00 (not sure if related) but on angular V12 when using digit-only v2.2.3 everything works as expected, using the following code:

Using angular forms with FormGroup

<input type="text" 
           digitOnly maxlength="3" inputmode="numeric" pattern="[0-9]*"  
           class="form-control" placeholder="Amount required?"
           id="qty" formControlName="qty">

I have also tried just using digitOnly with the same results.

However, when upgrading to v3.0.0 in the input field it allows me to enter anything, e.g. "aaa"

But the maxlength attribute is still honoured/validated.

Not sure what else may be of use to diagnose this further? But package.json is here:

    "@angular/animations": "~12.0.0",
    "@angular/cdk": "^12.0.0",
    "@angular/common": "~12.0.0",
    "@angular/compiler": "~12.0.0",
    "@angular/core": "~12.0.0",
    "@angular/forms": "~12.0.0",
    "@angular/google-maps": "^12.0.0",
    "@angular/localize": "^12.0.0",
    "@angular/platform-browser": "~12.0.0",
    "@angular/platform-browser-dynamic": "~12.0.0",
    "@angular/platform-server": "~12.0.0",
    "@angular/router": "~12.0.0",

Does not support hotkeys in another language

Does not support hotkeys when the keyboard is in another language

(e.key === 'a' && e.ctrlKey) || // Allow: Ctrl+A
(e.key === 'c' && e.ctrlKey) || // Allow: Ctrl+C
(e.key === 'v' && e.ctrlKey) || // Allow: Ctrl+V

I think the best way is to replace it with

(e.code === 'KeyA' && e.ctrlKey) || // Allow: Ctrl+A
(e.code === 'KeyC' && e.ctrlKey) || // Allow: Ctrl+C
(e.code === 'KeyV' && e.ctrlKey) || // Allow: Ctrl+V

input type="number" does not work properly

Hi @changhuixu

First of all thanks for the good work. The lib is pretty good and has a lot of edge case validations.

But why are all the samples using input type="text" which technically sounds wrong because we are expecting a number input.

Our input controls needs a spinner which can be controlled by arrow keys on the keyboard. But when we add digitOnly to the input type="number" there are two problems arise

  • Arrow keys to control to increase / decrease the values does not work
  • Also when i try to manually enter the max value it does not allow me to enter.

Please find the reproducible link here for this bug 🐛 - CodeSandbox

Licence File

Hi
Please could you include the Licence file in the npm package?
Thanks

if the control has a maxLength set then when pasting a value on top of an existing value , the pasted value is incorrect

for example lets say that we have an input such as:
<input type='text' maxLength="10" digitOnly />
and the input value is 1234567890
then I select and copy existing value and try to paste into the control => the new value will be an empty string

I narrowed down the problem to the allowedLength calculation in the sanitizeInput method
as far as I can say something is wrong with this code section.

 if (maxLength > 0) {

      // the input element has maxLength limit

      const allowedLength =

        maxLength -

        this.inputElement.value.length +

        (result.includes(`${this.negativeSign}`) ? 1 : 0);

      result = allowedLength > 0 ? result.substring(0, allowedLength) : '';

    }

could you please check ?

I'm using angular 16.1.4 and version 3.2.1 of this repo,
but I've check previous versions of angular (14 and 15.2.8) and in the demo page
this bug exist there too.

decimalSeparator as array

Hello,

Is it possible to make the decimalSeparator an array ? In my case the user can enter in the same input xx.xx or xx,xx, so the decimalSeparator = ['.',',']

Error after build the project

Good Day,

I just install this control and follow the guideline from the documents but after building the project i get the error below. May i know which part i have miss out? Thanks~

ERROR in ../node_modules/@uiowa/digit-only/lib/digit-only.directive.d.ts:23:9 - error TS1086: An accessor cannot be declared in an ambient context.

23 get precision(): number;
~~~~~~~~~

angular 10 compatibility

when trying to update from angular 9 to 10. I've got this error:

Package "@uiowa/digit-only" has an incompatible peer dependency to "tslib" (requires "^1.10.0", would install "2.0.0")

Negative value

Hey there,

Nice job on this directive, but how can we manage negative input ?
We have @input() min set to -Infinity but we cannot set '-' char ?

Any solution ?

Thx for advance.

Chrome autofill bypasses directive

when I click an input and chrome's autofill dropbox shows up, I can select a text entry and it will fill in inputs with the digit-only directive with those non-digit characters

Error in inionic

Error: node_modules/@uiowa/digit-only/lib/digit-only.directive.d.ts:27:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.
[ng] 27 static ɵfac: i0.ɵɵFactoryDeclaration<DigitOnlyDirective, never>;
[ng] ~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/digit-only.directive.d.ts:28:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵDirectiveDeclaration'.
[ng] 28 static ɵdir: i0.ɵɵDirectiveDeclaration<DigitOnlyDirective, "[digitOnly]", never, { "decimal": "decimal"; "decimalSeparator": "decimalSeparator"; "min": "min"; "max": "max"; "pattern": "pattern"; }, {}, never>;
[ng] ~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/digit-only.module.d.ts:5:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.
[ng] 5 static ɵfac: i0.ɵɵFactoryDeclaration<DigitOnlyModule, never>;
[ng] ~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/digit-only.module.d.ts:6:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵNgModuleDeclaration'.
[ng] 6 static ɵmod: i0.ɵɵNgModuleDeclaration<DigitOnlyModule, [typeof i1.DigitOnlyDirective, typeof i2.MaskDirective], never, [typeof i1.DigitOnlyDirective, typeof i2.MaskDirective]>;
[ng] ~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/digit-only.module.d.ts:7:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵInjectorDeclaration'.
[ng] 7 static ɵinj: i0.ɵɵInjectorDeclaration;
[ng] ~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/mask.directive.d.ts:12:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.
[ng] 12 static ɵfac: i0.ɵɵFactoryDeclaration<MaskDirective, never>;
[ng] ~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/@uiowa/digit-only/lib/mask.directive.d.ts:13:21 - error TS2694: Namespace '"/Users/davidgarcia/Desktop/app/node_modules/@angular/core/core"' has no exported member 'ɵɵDirectiveDeclaration'.
[ng] 13 static ɵdir: i0.ɵɵDirectiveDeclaration<MaskDirective, "[mask]", never, {}, {}, never>;
[ng] ~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 235:10-28
[ng] "export 'ɵɵFactoryTarget' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 367:10-28
[ng] "export 'ɵɵFactoryTarget' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 412:10-28
[ng] "export 'ɵɵFactoryTarget' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 262:0-27
[ng] "export 'ɵɵngDeclareClassMetadata' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 380:0-27
[ng] "export 'ɵɵngDeclareClassMetadata' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 429:0-27
[ng] "export 'ɵɵngDeclareClassMetadata' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 227:26-47
[ng] "export 'ɵɵngDeclareFactory' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 359:21-42
[ng] "export 'ɵɵngDeclareFactory' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 406:23-44
[ng] "export 'ɵɵngDeclareFactory' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 422:23-45
[ng] "export 'ɵɵngDeclareInjector' (imported as 'i0') was not found in '@angular/core'
[ng] Error: ./node_modules/@uiowa/digit-only/fesm2015/uiowa-digit-only.js 414:23-45
[ng] "export 'ɵɵngDeclareNgModule' (imported as 'i0') was not found in '@angular/core'
[ng] 26.js | - | 0 bytes
[ng] 27.js | - | 0 bytes
[ng] 28.js | - | 0 bytes
[ng] 29.js | - | 0 bytes
[ng] 30.js | - | 0 bytes
[ng] 31.js | - | 0 bytes
[ng] 32.js | - | 0 bytes
[ng] 33.js | - | 0 bytes
[ng] 34.js | - | 0 bytes
[ng] 35.js | - | 0 bytes
[ng] 36.js | - | 0 bytes
[ng] 37.js | - | 0 bytes
[ng] 38.js | - | 0 bytes
[ng] 39.js | - | 0 bytes
[ng] 40.js | - | 0 bytes
[ng] 41.js | - | 0 bytes
[ng] 42.js | - | 0 bytes
[ng] common.js | common | 0 bytes
[ng] data-protection-data-protection-module.js | data-protection-data-protection-module | 0 bytes
[ng] defaultfaq-faq-modulehome-home-moduleinfo-pcr-info-pcr-modulemore-more-modulepassenger-data-pas69049f62.js | defaultfaq-faq-modulehome-home-moduleinfo-pcr-info-pcr-modulemore-more-modulepassenger-data-pas69049f62 | 0 bytes
[ng] defaulthome-home-modulepassenger-data-passenger-data-modulepassenger-form-passenger-form-module.js | defaulthome-home-modulepassenger-data-passenger-data-modulepassenger-form-passenger-form-module | 0 bytes
[ng] defaultinfo-email-info-email-modulepassenger-data-passenger-data-modulepassenger-form-passenger-f9474c0f2.js | defaultinfo-email-info-email-modulepassenger-data-passenger-data-modulepassenger-form-passenger-f9474c0f2 | 0 bytes
[ng] defaultpassenger-data-passenger-data-modulepassenger-form-passenger-form-module.js | defaultpassenger-data-passenger-data-modulepassenger-form-passenger-form-module | 0 bytes
[ng] faq-faq-module.js | faq-faq-module | 0 bytes
[ng] focus-visible-f4ad4f1a-js.js | focus-visible-f4ad4f1a-js | 0 bytes
[ng] home-home-module.js | home-home-module | 0 bytes
[ng] info-email-info-email-module.js | info-email-info-email-module | 0 bytes
[ng] info-pcr-info-pcr-module.js | info-pcr-info-pcr-module | 0 bytes
[ng] input-shims-73f15161-js.js | input-shims-73f15161-js | 0 bytes
[ng] keyboard-5742b5da-js.js | keyboard-5742b5da-js | 0 bytes
[ng] more-more-module.js | more-more-module | 0 bytes
[ng] passenger-data-passenger-data-module.js | passenger-data-passenger-data-module | 0 bytes
[ng] passenger-form-passenger-form-module.js | passenger-form-passenger-form-module | 0 bytes
[ng] polyfills-core-js.js | polyfills-core-js | 0 bytes
[ng] polyfills-css-shim.js | polyfills-css-shim | 0 bytes
[ng] polyfills-dom.js | polyfills-dom | 0 bytes
[ng] shadow-css-a3f00b33-js.js | shadow-css-a3f00b33-js | 0 bytes
[ng] status-tap-bdecfebf-js.js | status-tap-bdecfebf-js | 0 bytes
[ng] swipe-back-ee838cf8-js.js | swipe-back-ee838cf8-js | 0 bytes
[ng] swiper-bundle-44a9b1f9-js.js | swiper-bundle-44a9b1f9-js | 0 bytes
[ng] tap-click-cc1ae2b2-js.js | tap-click-cc1ae2b2-js | 0 bytes
[ng] Build at: 2021-05-21T07:10:26.436Z - Hash: f8d116e5322be4a666f6 - Time: 21450ms

[INFO] Development server running!

Local: http://localhost:8100

Use Ctrl+C to quit this process

[INFO] Browser window opened to http://localhost:8100!

image

Paste String error Join

please treat the error when paste a field that is not a number
Error: Cannot read property 'join' of null

Cursor jumping when editing input on Safari

Hello,
I found a small bug on Safari when editing the input value.
It may have something to do with the .setRangeText method, maybe safari is not fully supporting this method. In any way this bug doesn't happen on Chrome.

If you type a number (ex: 1245) and then place your cursor after the 2 to add a digit (3), it will add the digit, but will make the cursor jump at the end of the number (after the 5), which is not the expected behaviour.
Same if you delete a digit in the middle of the number. Same if you paste a digit in the middle of the number. It will always teleport the cursor at the end of the number.

(I am on safari 14.0.2, mac os BigSur)

Thanks for your module it is very useful,
Best regards,
JB

Big numbers in scientific format

Hello,

I was playing with the input and typing huge numbers. Above 16 digits there are strange behaviours happening.
Between 16 and 20 digits, numbers are rounding themselves to the nearest even number (for the 17th digit) and then whatever the digit inputed, it will only add zeros.

And for more than 21 digits, the number is converted to scientific format, which is a surprising behaviour when you are typing a number (but copied/pasted number are not converted). For even larger numbers, it is rounded to Infinity and then NaN.

Maybe instead of NaN and Infinity which can cause some issue in the algorithms filled with the input data, we can add an new condition in the onKeyDown method of the directive, to block, by default, too large number (number that can't be handle by javascript). I know that I can use a max parameters on my input, but I am wondering whether it should be a default behaviour.
And we should also prevent any conversion to scientific format.

Space characters are accepted

For some reason space characters are accepted. Digit only implies that only numeric characters should be accepted.

Can't disable paste

I want to disable paste. But using (paste)="false" with digitOnly directive doesn't work.

   <input [(ngModel)]="test" placeholder="Enter Value" type="text" digitOnly
                         [pattern]="getInputPattern()" (input)="onInputChange()" (paste)="false">

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.