Skip to content

Commit bbf5735

Browse files
committed
fix(pat auto suggest): Fix issue with pat-auto-submit.
Also dispatch a input event after a value has changed to let auto-submit do a form submit. This fixes an issue introduced in Patternslib 7.0.0. Note: this will be revisited when reworking auto-submit and input-change-events for standard JavaScript event compatibility.
1 parent d4d2e99 commit bbf5735

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/pat/auto-suggest/auto-suggest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export default Base.extend({
108108
// Select2 also triggers a click event, which we will use here to
109109
// trigger a standard JS change event.
110110
this.el.dispatchEvent(events.change_event());
111+
// Also dispatch a ``input`` event for ``input-change-events``
112+
// and pat-auto-suggest to pick this up.
113+
// TODO: Revisit after ``input-change-events`` is removed.
114+
this.el.dispatchEvent(events.input_event());
111115
});
112116

113117
// Clear values on reset.

src/pat/auto-suggest/auto-suggest.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("pat-autosuggest", function () {
4444
});
4545

4646
afterEach(function () {
47-
$("#lab").remove();
47+
document.body.innerHTML = "";
4848
jest.restoreAllMocks();
4949
});
5050

@@ -220,4 +220,28 @@ describe("pat-autosuggest", function () {
220220
testutils.removeSelect2();
221221
});
222222
});
223+
224+
describe("4 - Integration...", function () {
225+
it("4.1 - Works with pat-auto-submit", async function () {
226+
document.body.innerHTML = `
227+
<input
228+
type="text"
229+
class="pat-autosuggest pat-autosubmit"
230+
data-pat-autosuggest="words: apple, orange, pear"
231+
data-pat-autosubmit="delay:0" />
232+
`;
233+
234+
const pattern_autosubmit = (await import("../auto-submit/auto-submit")).default; // prettier-ignore
235+
const input = document.querySelector("input");
236+
new pattern(input);
237+
const instance_autosubmit = new pattern_autosubmit(input);
238+
const spy = jest.spyOn(instance_autosubmit.$el, "submit");
239+
await utils.timeout(1); // wait a tick for async to settle.
240+
241+
$(".select2-input").click();
242+
$(document.querySelector(".select2-result")).mouseup();
243+
244+
expect(spy).toHaveBeenCalled();
245+
});
246+
});
223247
});

0 commit comments

Comments
 (0)