From 79dc66f1ed7018834838419aa1448c5ef48c4c49 Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 7 Jun 2017 17:21:51 +0200 Subject: [PATCH 1/8] Update ctr-input.ts --- src/directives/ctr-input.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/directives/ctr-input.ts b/src/directives/ctr-input.ts index 7332cf3..2adcc0d 100644 --- a/src/directives/ctr-input.ts +++ b/src/directives/ctr-input.ts @@ -27,6 +27,7 @@ export class CtrInput { @Input("overrideSuggested") public overrideSuggested = false; @Input("fillHighlighted") public fillHighlighted = true; @Input("openOnFocus") public openOnFocus = false; + @Input("forceSelection") public forceSelection = true; @Output() public ngModelChange: EventEmitter = new EventEmitter(); @@ -99,7 +100,9 @@ export class CtrInput { if (this.completer.hasHighlighted()) { event.preventDefault(); } - this.handleSelection(); + if (!this.forceSelection || this.completer._hasHighlighted) { + this.handleSelection(); + } } else if (event.keyCode === KEY_DW) { event.preventDefault(); this.completer.open(); @@ -108,7 +111,9 @@ export class CtrInput { event.preventDefault(); this.completer.prevRow(); } else if (event.keyCode === KEY_TAB) { - this.handleSelection(); + if (!this.forceSelection || this.completer._hasHighlighted) { + this.handleSelection(); + } } else if (event.keyCode === KEY_ES) { // This is very specific to IE10/11 #272 // without this, IE clears the input text From cb1bc7158cd7bbb200ea7380a67d70ef19a81f58 Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 7 Jun 2017 17:22:53 +0200 Subject: [PATCH 2/8] Update completer-cmp-md.html --- demo/completer-cmp-md.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/completer-cmp-md.html b/demo/completer-cmp-md.html index 9d1de79..5211aaf 100644 --- a/demo/completer-cmp-md.html +++ b/demo/completer-cmp-md.html @@ -1,6 +1,6 @@
- @@ -25,4 +25,4 @@
- \ No newline at end of file + From 114add0ca2a241ad8659beeac04db835cd00f418 Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 7 Jun 2017 17:24:04 +0200 Subject: [PATCH 3/8] Update completer-cmp.ts --- src/components/completer-cmp.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/completer-cmp.ts b/src/components/completer-cmp.ts index b5a33ee..8c5499e 100644 --- a/src/components/completer-cmp.ts +++ b/src/components/completer-cmp.ts @@ -135,6 +135,7 @@ export class CompleterCmp implements OnInit, ControlValueAccessor, AfterViewChec @Input() public openOnFocus = false; @Input() public initialValue: any; @Input() public autoHighlight = false; + @Input() public forceSelection = false; @Output() public selected = new EventEmitter(); @Output() public highlighted = new EventEmitter(); From 12376231c9282fb3b1596ef4fc6718127acb1728 Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 7 Jun 2017 17:27:31 +0200 Subject: [PATCH 4/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 22c2bc6..fb0c6dd 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Add the following to `System.js` map configuration: |overrideSuggested|If true will override suggested and set the model with the value in the input field.|boolean|No|false| |openOnFocus|If true will open the dropdown and perform search when the input gets the focus.|boolean|No|false| |fillHighlighted|If true will set the model with the value in the input field when item is highlighted.|boolean|No|true| +|forceSelection|If true will prevent from closing dropdown on Enter and Tab keys down if no selection was made.|boolean|No|true| |pause|Number of msec. to wait before searching.|number|No|250| |placeholder|Placeholder text for the search field.|string|No|| |textNoResults|Text displayed when the search returned no results. if the string is falsy it won't be displayed|string|No| From 38b7ce0f74cbadad273aa246b3e67ed16492ab3d Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 7 Jun 2017 17:29:41 +0200 Subject: [PATCH 5/8] Update ctr-input.ts --- src/directives/ctr-input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directives/ctr-input.ts b/src/directives/ctr-input.ts index 2adcc0d..4fe5b43 100644 --- a/src/directives/ctr-input.ts +++ b/src/directives/ctr-input.ts @@ -27,7 +27,7 @@ export class CtrInput { @Input("overrideSuggested") public overrideSuggested = false; @Input("fillHighlighted") public fillHighlighted = true; @Input("openOnFocus") public openOnFocus = false; - @Input("forceSelection") public forceSelection = true; + @Input("forceSelection") public forceSelection = false; @Output() public ngModelChange: EventEmitter = new EventEmitter(); From 985b5a132c9870a6297509d42996f7e039d7f8d2 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Sat, 16 Sep 2017 03:10:47 +0200 Subject: [PATCH 6/8] - Using private prop ? lol - DRY --- README.md | 2 +- src/directives/ctr-input.ts | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fb0c6dd..0ddc746 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Add the following to `System.js` map configuration: |overrideSuggested|If true will override suggested and set the model with the value in the input field.|boolean|No|false| |openOnFocus|If true will open the dropdown and perform search when the input gets the focus.|boolean|No|false| |fillHighlighted|If true will set the model with the value in the input field when item is highlighted.|boolean|No|true| -|forceSelection|If true will prevent from closing dropdown on Enter and Tab keys down if no selection was made.|boolean|No|true| +|forceSelection|If true will prevent from closing dropdown on Enter and Tab keys down if no selection was made.|boolean|No|false| |pause|Number of msec. to wait before searching.|number|No|250| |placeholder|Placeholder text for the search field.|string|No|| |textNoResults|Text displayed when the search returned no results. if the string is falsy it won't be displayed|string|No| diff --git a/src/directives/ctr-input.ts b/src/directives/ctr-input.ts index 4fe5b43..4091827 100644 --- a/src/directives/ctr-input.ts +++ b/src/directives/ctr-input.ts @@ -100,9 +100,7 @@ export class CtrInput { if (this.completer.hasHighlighted()) { event.preventDefault(); } - if (!this.forceSelection || this.completer._hasHighlighted) { - this.handleSelection(); - } + this.handleSelection(); } else if (event.keyCode === KEY_DW) { event.preventDefault(); this.completer.open(); @@ -111,9 +109,7 @@ export class CtrInput { event.preventDefault(); this.completer.prevRow(); } else if (event.keyCode === KEY_TAB) { - if (!this.forceSelection || this.completer._hasHighlighted) { - this.handleSelection(); - } + this.handleSelection(); } else if (event.keyCode === KEY_ES) { // This is very specific to IE10/11 #272 // without this, IE clears the input text @@ -179,7 +175,8 @@ export class CtrInput { this.completer.selectCurrent(); } else if (this.overrideSuggested) { this.completer.onSelected({ title: this.searchStr, originalObject: null }); - } else { + } + else if (!this.forceSelection) { this.completer.clear(); } } From 5d8bc3f2c5c5e8ade784f15de20b314a7fe463e2 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Sat, 16 Sep 2017 05:32:18 +0200 Subject: [PATCH 7/8] Update demo + tpl --- demo/completer-cmp-md.ts | 1 + demo/native-cmp.html | 26 ++++++++++++++++++++++++++ src/components/completer-cmp.ts | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/demo/completer-cmp-md.ts b/demo/completer-cmp-md.ts index 73fed69..3770d2b 100644 --- a/demo/completer-cmp-md.ts +++ b/demo/completer-cmp-md.ts @@ -33,6 +33,7 @@ export class CompleterCmpMd implements OnInit, ControlValueAccessor { @Input() public overrideSuggested = false; @Input() public fillHighlighted = true; @Input() public clearSelected = false; + @Input() public forceSelection = false; @Input() public placeholder = ""; @Input() public matchClass: string; @Input() public textSearching = TEXT_SEARCHING; diff --git a/demo/native-cmp.html b/demo/native-cmp.html index 0c51854..b017e26 100644 --- a/demo/native-cmp.html +++ b/demo/native-cmp.html @@ -293,6 +293,32 @@

Do not set input value when item is highlighted

+

Force selection

+

Local data of colors; with minSearchLength, textSearching, clearUnselected and forceSelection + = false

+ +
+
+
+
+ + + +
+
+

{{color5}}

+
+
+
+
+

Events

Event triggering with onBlur and onFocus events.

diff --git a/src/components/completer-cmp.ts b/src/components/completer-cmp.ts index d5ea4fc..08df46b 100644 --- a/src/components/completer-cmp.ts +++ b/src/components/completer-cmp.ts @@ -27,8 +27,8 @@ const COMPLETER_CONTROL_VALUE_ACCESSOR = { From eca9e2012d4eee44e14fa23e35375f95b753b61b Mon Sep 17 00:00:00 2001 From: gRoussac Date: Sat, 16 Sep 2017 05:36:19 +0200 Subject: [PATCH 8/8] // typo --- demo/native-cmp.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/demo/native-cmp.html b/demo/native-cmp.html index b017e26..c07bfcc 100644 --- a/demo/native-cmp.html +++ b/demo/native-cmp.html @@ -294,8 +294,7 @@

Do not set input value when item is highlighted

Force selection

-

Local data of colors; with minSearchLength, textSearching, clearUnselected and forceSelection - = false

+

Local data of colors; with minSearchLength, textSearching, clearUnselected and forceSelection