Skip to content

Commit

Permalink
Bug: Fixes x-model.fill when used with debounce (#4103)
Browse files Browse the repository at this point in the history
* 🧪 Adds failing .fill.debounce test

* 🐛 Fixes .fill.debounce conflict
  • Loading branch information
ekwoka authored Mar 21, 2024
1 parent fce7e37 commit 4590592
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/alpinejs/src/directives/x-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ directive('model', (el, { modifiers, expression }, { effect, cleanup }) => {
if (modifiers.includes('fill'))
if ([undefined, null, ''].includes(getValue())
|| (el.type === 'checkbox' && Array.isArray(getValue()))) {
el.dispatchEvent(new Event(event, {}));
setValue(
getInputValue(el, modifiers, { target: el }, getValue())
);
}
// Register the listener removal callback on the element, so that
// in addition to the cleanup function, x-modelable may call it.
Expand Down
12 changes: 12 additions & 0 deletions tests/cypress/integration/directives/x-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,15 @@ test(
}
);

test(
'x-model with fill and debounce still fills value',
html`
<div x-data="{ a: '' }">
<input type="text" x-model.fill.debounce="a" value="hello" />
</div>
`,
({ get }) => {
get('[x-data]').should(haveData('a', 'hello'));
}
);

0 comments on commit 4590592

Please sign in to comment.