From f4100c3be12b91f4349ff76c86b8b9f451a57a42 Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Thu, 14 Jul 2022 10:16:34 +0100 Subject: [PATCH 1/6] Option for whether to clear output fields on submit --- README.md | 5 +++-- package-lock.json | 4 ++-- package.json | 2 +- src/Find.ts | 9 ++++++++- src/Types.ts | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c3669c1..5648353 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ npm install getaddress-find ``` ### Or CDN ``` - + ``` ## Usage @@ -79,7 +79,8 @@ getAddress.find( id:'getaddress_button', /* The id of the botton' */ class:'', /* The class of the botton' */ label:'Search', /* The label of the botton' */ - disabled_message:'disabled message' /* The disabled message of the botton' */ + disabled_message:'disabled message', /* The disabled message of the botton' */ + clear_on_submit: true /* Clear output fields on submit ' */ }, dropdown:{ id:'getaddress_dropdown', /* The id of the dropdown' */ diff --git a/package-lock.json b/package-lock.json index 931693e..818dd02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "getaddress-find", - "version": "1.0.9", + "version": "2.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "getaddress-find", - "version": "1.0.9", + "version": "2.0.2", "license": "MIT", "dependencies": { "getaddress-api": "^1.1.13" diff --git a/package.json b/package.json index 071626b..86d09bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getaddress-find", - "version": "2.0.2", + "version": "2.0.3", "description": "GetAddress.io - Find by postcode plug-in", "main": "dist/getaddress-find.mjs", "type": "module", diff --git a/src/Find.ts b/src/Find.ts index 2f62868..bec1f92 100644 --- a/src/Find.ts +++ b/src/Find.ts @@ -53,6 +53,10 @@ export default class Find{ let addressResult = await this.getAddress.get(id); if(addressResult.isSuccess){ let success = addressResult.toSuccess(); + if (!this.button.config.clear_on_submit) + { + this.clearAll(); + } this.outputFields.bind(success.address); AddressSelectedEvent.dispatch(this.context,success.address); @@ -117,7 +121,10 @@ export default class Find{ if(query && query !== this.input.config.label) { button.disable(); - this.clearAll(); + if(this.button.config.clear_on_submit) + { + this.clearAll(); + } await this.lookup(query); } return false; diff --git a/src/Types.ts b/src/Types.ts index f2ab08a..69c73a4 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -32,7 +32,7 @@ export class ButtonConfig extends Config id = "getaddress_button" + this.getIdSuffix(); class = ""; disabled_message= "Fetching Addresses..."; - + clear_on_submit:boolean = true; } export class DropdownConfig extends Config From 07f4fec7420f99d489cf6b975015976917b60e5a Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Thu, 14 Jul 2022 11:04:35 +0100 Subject: [PATCH 2/6] Allow setting initial value of the input --- README.md | 6 ++++-- src/Input.ts | 30 ++---------------------------- src/Types.ts | 5 +++-- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 5648353..8e9d102 100644 --- a/README.md +++ b/README.md @@ -73,14 +73,16 @@ getAddress.find( id:'getaddress_input', /* The id of the textbox' */ name:'getaddress_input', /* The name of the textbox' */ class:'', /* The class of the textbox' */ - label:'Enter your Postcode' /* The label of the textbox' */ + label:'Enter your Postcode', /* The label of the textbox (deprecated, use placeholder)' */ + placeholder:'Enter your Postcode', /* The placeholder of the textbox' */ + value:'' /* The initial value of the textbox' */ }, button:{ id:'getaddress_button', /* The id of the botton' */ class:'', /* The class of the botton' */ label:'Search', /* The label of the botton' */ disabled_message:'disabled message', /* The disabled message of the botton' */ - clear_on_submit: true /* Clear output fields on submit ' */ + clear_on_submit:true /* Clear output fields on submit ' */ }, dropdown:{ id:'getaddress_dropdown', /* The id of the dropdown' */ diff --git a/src/Input.ts b/src/Input.ts index 02e5a4f..253407b 100644 --- a/src/Input.ts +++ b/src/Input.ts @@ -14,7 +14,8 @@ export default class Input let input = document.createElement("input"); input.id = this.config.id; input.type = "text"; - input.value = this.config.label; + input.placeholder = this.config.label !== '' ? this.config.label : this.config.placeholder; + input.value = this.config.value; if(this.config.class) { @@ -24,28 +25,8 @@ export default class Input input.name = this.config.name; input.autocomplete = "off"; - let styleAttr:Attr = this.getDefaultStyle(); - input.attributes.setNamedItem(styleAttr); - input.addEventListener("submit", ()=>{return false}); - input.addEventListener("focus", ()=> - { - input.removeAttribute('style'); - if(input.value === this.config.label){ - input.value = ''; - } - }); - - input.addEventListener("blur", ()=> - { - if(!input.value){ - input.value = this.config.label; - let styleAttr:Attr = this.getDefaultStyle(); - input.attributes.setNamedItem(styleAttr); - } - }); - let container = document.getElementById(this.config.container_id); if(container){ @@ -55,13 +36,6 @@ export default class Input return input; } - private getDefaultStyle = ()=> - { - let styleAttr:Attr = document.createAttribute("style"); - styleAttr.value = this.config.muted_style; - return styleAttr; - } - onKeyPress = (action:()=>void) => { this.inputElement.addEventListener("keypress", (e) => diff --git a/src/Types.ts b/src/Types.ts index 69c73a4..ee9416a 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -18,8 +18,9 @@ export class Config{ export class InputConfig extends Config { - label:string = "Search.."; - muted_style:string = "color:#CBCBCB;"; + label:string = ""; + placeholder:string = "Search.."; + value:string = ""; class = ""; id = "getaddress_input" + this.getIdSuffix(); name = "getaddress_input" + this.getIdSuffix(); From a749816f5d829837d0aced6c243a88802f7472d7 Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Thu, 14 Jul 2022 11:07:16 +0100 Subject: [PATCH 3/6] Build additional files with no version in filename so these are always latest release --- README.md | 2 +- rollup.config.js | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8e9d102..44ec9cf 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ npm install getaddress-find ``` ### Or CDN ``` - + ``` ## Usage diff --git a/rollup.config.js b/rollup.config.js index 27e1eb4..77a518d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,15 +17,21 @@ export default [ }, { input: "src/GetAddress.ts", - output: + output: [ { file:"dist/getaddress-find-" + version + ".js", format:"iife", name:'getAddress', sourcemap: "inline" + }, + { + file:"dist/getaddress-find.js", + format:"iife", + name:'getAddress', + sourcemap: "inline" } - - ,plugins:[nodeResolve(),ts( + ], + plugins:[nodeResolve(),ts( {tsconfig: { declaration: false }} @@ -33,12 +39,18 @@ export default [ }, { input: "dist/getaddress-find.mjs", - output: + output: [ { file:"dist/getaddress-find-" + version + ".min.js", format:"iife", name:'getAddress' }, + { + file:"dist/getaddress-find.min.js", + format:"iife", + name:'getAddress' + } + ], plugins:[terser()] } ] \ No newline at end of file From 823d5b6e41630c8d94aa1d506f62fdb0370796fd Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Thu, 14 Jul 2022 11:44:12 +0100 Subject: [PATCH 4/6] Use version number in CDN link to avoid browser cache issues --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44ec9cf..8e9d102 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ npm install getaddress-find ``` ### Or CDN ``` - + ``` ## Usage From 136954d89bc287061db0e398f71265c51deefcfa Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Thu, 14 Jul 2022 11:59:40 +0100 Subject: [PATCH 5/6] Revert building additional files with no version in filename --- rollup.config.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 77a518d..27e1eb4 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,21 +17,15 @@ export default [ }, { input: "src/GetAddress.ts", - output: [ + output: { file:"dist/getaddress-find-" + version + ".js", format:"iife", name:'getAddress', sourcemap: "inline" - }, - { - file:"dist/getaddress-find.js", - format:"iife", - name:'getAddress', - sourcemap: "inline" } - ], - plugins:[nodeResolve(),ts( + + ,plugins:[nodeResolve(),ts( {tsconfig: { declaration: false }} @@ -39,18 +33,12 @@ export default [ }, { input: "dist/getaddress-find.mjs", - output: [ + output: { file:"dist/getaddress-find-" + version + ".min.js", format:"iife", name:'getAddress' }, - { - file:"dist/getaddress-find.min.js", - format:"iife", - name:'getAddress' - } - ], plugins:[terser()] } ] \ No newline at end of file From 7ed7aef1ccec89777240f31f8537f0c5bc7c4328 Mon Sep 17 00:00:00 2001 From: Chris Nolan Date: Mon, 18 Jul 2022 13:47:43 +0100 Subject: [PATCH 6/6] Updated package-lock.json --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 818dd02..2b40e4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "getaddress-find", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "getaddress-find", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "dependencies": { "getaddress-api": "^1.1.13"