Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not trigger fill checkpoint for hidden fields #358

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ function addFormTracking(parent) {
form.addEventListener('submit', (e) => sampleRUM('formsubmit', { target: targetSelector(e.target), source: sourceSelector(e.target) }), { once: true });
let lastSource;
form.addEventListener('change', (e) => {
const source = sourceSelector(e.target);
if (source !== lastSource) {
sampleRUM('fill', { source });
lastSource = source;
if (e.target.checkVisibility()) {
const source = sourceSelector(e.target);
if (source !== lastSource) {
sampleRUM('fill', { source });
lastSource = source;
}
}
});
form.addEventListener('focusin', (e) => {
Expand Down
24 changes: 24 additions & 0 deletions test/it/fill.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

<head>
<title>Test Runner</title>
<style>
.hidden-div {
display: none;
}
</style>
<script>
// we load from localhost, and have the ability to
// change the scripts that are being served. Check the
Expand Down Expand Up @@ -54,6 +59,10 @@
<div id="editable-element-inside-form" contenteditable="true">
Editable element inside form
</div>
<div class="hidden-div">
<input type="text" name="hidden-field" id="hidden-field"/>
</div>
<input type="hidden" name="hidden-field-2" id="hidden-field-2"/>
</form>
<script type="module">
import { runTests } from '@web/test-runner-mocha';
Expand Down Expand Up @@ -129,6 +138,21 @@
assert(window.called[0].source === `form input[type='number']`,
`source ${window.called[0].source} is not form input[type='number']`);
});

it('filling hidden field dispatching change event', async () => {
const form = document.querySelector('form');
const hiddenField = form.querySelector('#hidden-field');
hiddenField.dispatchEvent(new Event('change', { bubbles: true }));
await window.wait(10);

assert(window.called.length === 0, `fill is called ${window.called.length} (Expected 0) times`);

const hiddenField2 = form.querySelector('#hidden-field-2');
hiddenField2.dispatchEvent(new Event('change', { bubbles: true }));
await window.wait(10);

assert(window.called.length === 0, `fill is called ${window.called.length} (Expected 0) times`);
});
});
});
</script>
Expand Down
Loading