Skip to content

Commit

Permalink
Remove input generator delay
Browse files Browse the repository at this point in the history
Fixes #15754
  • Loading branch information
brandonkelly committed Sep 20, 2024
1 parent 539313c commit bcffada
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Auto-generated handles, slugs, etc. now update immediately when the source input is changed. ([#15754](https://github.com/craftcms/cms/issues/15754))
- Fixed a bug where Table fields’ Default Values table could lose existing rows if they only consisted of Dropdown columns without configured options.

## 4.12.3 - 2024-09-14
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

24 changes: 6 additions & 18 deletions src/web/assets/cp/src/js/BaseInputGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Craft.BaseInputGenerator = Garnish.Base.extend(
settings: null,

listening: null,
timeout: null,
sourceVal: null,

init: function (source, target, settings) {
this.$source = $(source);
Expand Down Expand Up @@ -41,10 +41,11 @@ Craft.BaseInputGenerator = Garnish.Base.extend(
}

this.listening = true;
this.sourceVal = this.$source.val();

this.addListener(this.$source, 'input', 'onSourceTextChange');
this.addListener(this.$target, 'input', 'onTargetTextChange');
this.addListener(this.$form, 'submit', 'onFormSubmit');
this.addListener(this.$form, 'submit', 'updateTarget');
},

stopListening: function () {
Expand All @@ -54,21 +55,16 @@ Craft.BaseInputGenerator = Garnish.Base.extend(

this.listening = false;

if (this.timeout) {
clearTimeout(this.timeout);
}

this.removeAllListeners(this.$source);
this.removeAllListeners(this.$target);
this.removeAllListeners(this.$form);
},

onSourceTextChange: function () {
if (this.timeout) {
clearTimeout(this.timeout);
const val = this.$source.val();
if (this.sourceVal !== (this.sourceVal = val)) {
this.updateTarget();
}

this.timeout = setTimeout(this.updateTarget.bind(this), 250);
},

onTargetTextChange: function () {
Expand All @@ -77,14 +73,6 @@ Craft.BaseInputGenerator = Garnish.Base.extend(
}
},

onFormSubmit: function () {
if (this.timeout) {
clearTimeout(this.timeout);
}

this.updateTarget();
},

updateTarget: function () {
if (
!this.$target.is(':visible') &&
Expand Down

0 comments on commit bcffada

Please sign in to comment.