From cc696bf386e3ebbe72f14a7605bed886569da8f7 Mon Sep 17 00:00:00 2001 From: zn022285 Date: Fri, 4 Sep 2020 16:58:53 -0500 Subject: [PATCH] Chips autocomplete should have option to prevent user own input --- jade/page-contents/chips_content.html | 6 ++++++ js/chips.js | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/jade/page-contents/chips_content.html b/jade/page-contents/chips_content.html index 230d7548ef..bbe8a1dc1f 100644 --- a/jade/page-contents/chips_content.html +++ b/jade/page-contents/chips_content.html @@ -151,6 +151,12 @@

Options

{} Set autocomplete options. + + autocompleteOnly + Boolean + false + Toggles abililty to add custom value not in autocomplete list. + limit Integer diff --git a/js/chips.js b/js/chips.js index c47ff20bcd..4165dc63a8 100644 --- a/js/chips.js +++ b/js/chips.js @@ -6,6 +6,7 @@ placeholder: '', secondaryPlaceholder: '', autocompleteOptions: {}, + autocompleteOnly: false, limit: Infinity, onChipAdd: null, onChipSelect: null, @@ -267,9 +268,11 @@ } e.preventDefault(); - this.addChip({ - tag: this.$input[0].value - }); + if (!this.hasAutocomplete || (this.hasAutocomplete && !this.options.autocompleteOnly) ) { + this.addChip({ + tag: this.$input[0].value + }); + } this.$input[0].value = ''; // delete or left