From 103994099387ea098f51c8955efbb2e6f8a8343b Mon Sep 17 00:00:00 2001 From: Ray Herring Date: Fri, 28 Feb 2020 14:29:48 +0800 Subject: [PATCH 1/2] Add support to prompt for date, email, number, tel, and password. When prompt shows, had to make sure that setSelectionRange doesn't get run on anything but text, password, and url inputs --- lib/smalltalk.js | 13 +++++++++---- package.json | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/smalltalk.js b/lib/smalltalk.js index f4f039a..e913d88 100644 --- a/lib/smalltalk.js +++ b/lib/smalltalk.js @@ -92,10 +92,11 @@ function getButtons(options = {}) { function getType(options = {}) { const {type} = options; - - if (type === 'password') - return 'password'; - + const validTypes = ['date','email','number','tel','password']; + + if (validTypes.includes(type)) + return type; + return 'text'; } @@ -158,6 +159,10 @@ function showDialog(title, msg, value, buttons, options) { el.focus(); for (const el of find(dialog, ['input'])) { + if(el.getAttribute('type') === 'date') continue; + if(el.getAttribute('type') === 'email') continue; + if(el.getAttribute('type') === 'number') continue; + el.setSelectionRange(0, value.length); } diff --git a/package.json b/package.json index 971437d..3ae2ccd 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "eslint": "^6.1.0", "eslint-plugin-node": "^11.0.0", "eslint-plugin-putout": "^3.0.0", - "madrun": "^5.0.1", + "madrun": "^5.4.4", "nodemon": "^2.0.1", "nyc": "^15.0.0", "putasset": "^5.0.0", From d01b5457f275484bb02c5115a1c827a039713692 Mon Sep 17 00:00:00 2001 From: Ray Herring Date: Sun, 8 Mar 2020 05:39:29 +0800 Subject: [PATCH 2/2] lint --- lib/smalltalk.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/smalltalk.js b/lib/smalltalk.js index e913d88..a0c9e7d 100644 --- a/lib/smalltalk.js +++ b/lib/smalltalk.js @@ -93,10 +93,10 @@ function getButtons(options = {}) { function getType(options = {}) { const {type} = options; const validTypes = ['date','email','number','tel','password']; - + if (validTypes.includes(type)) - return type; - + return type; + return 'text'; } @@ -159,10 +159,15 @@ function showDialog(title, msg, value, buttons, options) { el.focus(); for (const el of find(dialog, ['input'])) { - if(el.getAttribute('type') === 'date') continue; - if(el.getAttribute('type') === 'email') continue; - if(el.getAttribute('type') === 'number') continue; - + if (el.getAttribute('type') === 'date') + continue; + + if (el.getAttribute('type') === 'email') + continue; + + if (el.getAttribute('type') === 'number') + continue; + el.setSelectionRange(0, value.length); }