From 9f5a358b347e367b2f3a5458d3d67b8598f325fb Mon Sep 17 00:00:00 2001 From: codermarcos Date: Sun, 28 Jan 2024 01:01:46 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix=20input=20set=20mask=20b?= =?UTF-8?q?ehaviour=20to=20form=20submit=20On=20branch=20fix/#67/problem-i?= =?UTF-8?q?nput-behaviour=20Changes=20to=20be=20committed:=20=09modified:?= =?UTF-8?q?=20=20=20cypress/e2e/v4.x.x/set-mask.cy.ts=20=09modified:=20=20?= =?UTF-8?q?=20src/set-mask.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress/e2e/v4.x.x/set-mask.cy.ts | 30 +++++++++++++++++++++++++++++- src/set-mask.ts | 3 +++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/v4.x.x/set-mask.cy.ts b/cypress/e2e/v4.x.x/set-mask.cy.ts index d7abe4c..894d9a1 100644 --- a/cypress/e2e/v4.x.x/set-mask.cy.ts +++ b/cypress/e2e/v4.x.x/set-mask.cy.ts @@ -88,6 +88,35 @@ describe( } ); + describe( + 'form submit', + () => { + beforeEach( + () => { + cy.visit(getUrl({ prefix: '$', suffix: 'CAD' }, '6.66')); + } + ); + + it( + 'should trigger form submit', + (done) => { + const spy = cy.spy().as('submit'); + + cy.get('form').then(form$ => { + form$.on('submit', e => { + e.preventDefault(); + spy(); + done(); + }); + }); + + cy.get('input').type('{Enter}'); + + cy.get('@submit').should('have.not.been.called'); + }, + ); + } + ); } ); @@ -307,7 +336,6 @@ describe( } ); - describe( 'negative numbers', () => { diff --git a/src/set-mask.ts b/src/set-mask.ts index 92eb2c2..0b4312a 100644 --- a/src/set-mask.ts +++ b/src/set-mask.ts @@ -222,6 +222,9 @@ function setMask( let start = element.selectionStart ?? lastPositionToNumber; let end = element.selectionEnd ?? lastPositionToNumber; + // Trigger input submit + if (e.key === 'Enter') return; + // Select all if (e.ctrlKey && e.key === 'a') return setCaretPosition([firstPositionToNumber, lastPositionToNumber]); From e9caf4fcaf4e1bedc7261600d19a7f9086c2c6b2 Mon Sep 17 00:00:00 2001 From: codermarcos Date: Sun, 28 Jan 2024 02:10:30 -0300 Subject: [PATCH 2/2] 4.1.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61d93f0..6bfd0a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-mask-money", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-mask-money", - "version": "4.1.1", + "version": "4.1.2", "hasInstallScript": true, "license": "Apache-2.0", "devDependencies": { diff --git a/package.json b/package.json index ad09588..279c1a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-mask-money", - "version": "4.1.1", + "version": "4.1.2", "private": false, "description": "Simple money mask developed with pure JavaScript. To run on Client Side and Server Side", "types": "./lib/simple-mask-money.d.ts",