From c3d19fe1bb989de2ae88d96a330f809a2b04516c Mon Sep 17 00:00:00 2001 From: Shea Bunge Date: Tue, 14 Mar 2023 22:56:42 +1100 Subject: [PATCH 1/3] Trigger a change event when original input value is updated. --- tagger.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tagger.js b/tagger.js index 7744b4a..0a9e688 100644 --- a/tagger.js +++ b/tagger.js @@ -161,6 +161,10 @@ this._build_completion(this._settings.completion.list); } }, + _update_input: function () { + this._input.value = this._tags.join(','); + this._input.dispatchEvent(new Event('change', { bubbles: true })) + }, // -------------------------------------------------------------------------------------- _add_events: function() { var self = this; @@ -192,7 +196,7 @@ var li = self._ul.querySelector('li:nth-last-child(2)'); self._ul.removeChild(li); self._tags.pop(); - self._input.value = self._tags.join(','); + self._update_input() } event.preventDefault(); } else if (event.keyCode === 32 && (event.ctrlKey || event.metaKey)) { @@ -318,7 +322,7 @@ } this._new_tag(name); this._tags.push(name); - this._input.value = this._tags.join(','); + this._update_input() return true; }, // -------------------------------------------------------------------------------------- @@ -340,7 +344,7 @@ this._tags = this._tags.filter(function(tag) { return name !== tag; }); - this._input.value = this._tags.join(','); + this._update_input() if (remove_dom) { var tags = Array.from(this._ul.querySelectorAll('.label')); var re = new RegExp('^\s*' + escape_regex(name) + '\s*$'); From 965086e4144230950baec0b5b83c79f12d1c8508 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 28 Jul 2023 15:32:35 +0200 Subject: [PATCH 2/3] add semicolons --- tagger.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tagger.js b/tagger.js index 0a9e688..3bd26dd 100644 --- a/tagger.js +++ b/tagger.js @@ -163,7 +163,7 @@ }, _update_input: function () { this._input.value = this._tags.join(','); - this._input.dispatchEvent(new Event('change', { bubbles: true })) + this._input.dispatchEvent(new Event('change', { bubbles: true })); }, // -------------------------------------------------------------------------------------- _add_events: function() { @@ -196,7 +196,7 @@ var li = self._ul.querySelector('li:nth-last-child(2)'); self._ul.removeChild(li); self._tags.pop(); - self._update_input() + self._update_input(); } event.preventDefault(); } else if (event.keyCode === 32 && (event.ctrlKey || event.metaKey)) { @@ -218,7 +218,7 @@ self._new_input_tag.value = ''; } } else { - var min = self._settings.completion.min_length; + var min = self._settings.completion.min_length; if (typeof self._settings.completion.list === 'function' && value.length >= min) { self.complete(value); } @@ -322,7 +322,7 @@ } this._new_tag(name); this._tags.push(name); - this._update_input() + this._update_input(); return true; }, // -------------------------------------------------------------------------------------- From 0492988ea5b6ac645e5971f51fdb98ba82c1efcc Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 28 Jul 2023 15:37:26 +0200 Subject: [PATCH 3/3] version 0.6.0 --- README.md | 6 ++++-- package.json | 2 +- tagger.css | 2 +- tagger.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8237de9..35dbf2b 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ |_ _|___ ___ ___ ___ ___ | | | .'| . | . | -_| _| |_| |__,|_ |_ |___|_| - |___|___| version 0.5.0 + |___|___| version 0.6.0 ``` # [Tagger: Zero dependency, Vanilla JavaScript Tag Editor](https://github.com/jcubic/tagger) -[![npm](https://img.shields.io/badge/npm-0.5.0-blue.svg)](https://www.npmjs.com/package/@jcubic/tagger) +[![npm](https://img.shields.io/badge/npm-0.6.0-blue.svg)](https://www.npmjs.com/package/@jcubic/tagger) ![Tag Editor widget in JavaScript](https://raw.githubusercontent.com/jcubic/tagger/master/screenshot.png) @@ -101,6 +101,8 @@ TypeScript definition file: [tagger.d.ts](https://github.com/jcubic/tagger/blob/master/tagger.d.ts) ## Changelog +### 0.6.0 +* add native change event for the original input element on tag change ### 0.5.0 * fix initialization [#23](https://github.com/jcubic/tagger/issues/23). Thanks to [James Lucas](https://github.com/lucasnetau) * add placeholder option. Thanks to [James Lucas](https://github.com/lucasnetau) diff --git a/package.json b/package.json index 1797263..7db323b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jcubic/tagger", - "version": "0.5.0", + "version": "0.6.0", "description": "Zero dependency, Vanilla JavaScript Tag Editor", "typings": "tagger.d.ts", "main": "tagger.js", diff --git a/tagger.css b/tagger.css index 25e6f54..6d3db32 100644 --- a/tagger.css +++ b/tagger.css @@ -3,7 +3,7 @@ * |_ _|___ ___ ___ ___ ___ * | | | .'| . | . | -_| _| * |_| |__,|_ |_ |___|_| - * |___|___| version 0.5.0 + * |___|___| version 0.6.0 * * Tagger - Zero dependency, Vanilla JavaScript Tag Editor * diff --git a/tagger.js b/tagger.js index 3bd26dd..bdddafd 100644 --- a/tagger.js +++ b/tagger.js @@ -3,7 +3,7 @@ * |_ _|___ ___ ___ ___ ___ * | | | .'| . | . | -_| _| * |_| |__,|_ |_ |___|_| - * |___|___| version 0.5.0 + * |___|___| version 0.6.0 * * Tagger - Zero dependency, Vanilla JavaScript Tag Editor *