Skip to content

Commit

Permalink
Merge pull request #309 from vdua/main
Browse files Browse the repository at this point in the history
bug: form id is not getting sent correctly in source selector
  • Loading branch information
vdua authored Oct 22, 2024
2 parents 006d4c2 + 9d21c60 commit 522344a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ function isButton(el) {
}

function getSourceContext(el) {
if (el.closest('form')) {
return `form${el.id ? `#${el.id}` : ''}`;
const formEl = el.closest('form');
if (formEl) {
return `form${formEl.id ? `#${formEl.id}` : ''}`;
}
const block = el.closest('.block[data-block-name]');
if (block) return `.${block.getAttribute('data-block-name')}`;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/dom.sourceSelector.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<input type="checkbox" class="a-checkbox"></input>
<textarea class="a-textarea"></textarea>
<input class="a-none"></input>
<div id="form-element">
<input type="text" class="a-text-inside-div"></input>
</div>
</form>

<form id="b-form">
Expand Down Expand Up @@ -53,6 +56,7 @@
expect(sourceSelector(document.querySelector('input[type="checkbox"'))).to.be.equal('form#a-form input[type=\'checkbox\'].a-checkbox');
expect(sourceSelector(document.querySelector('input.a-none'))).to.be.equal('form#a-form input[type=\'\'].a-none');
expect(sourceSelector(document.querySelector('textarea'))).to.be.equal('form#a-form textarea.a-textarea');
expect(sourceSelector(document.querySelector('input.a-text-inside-div'))).to.be.equal('form#a-form input[type=\'text\'].a-text-inside-div');

expect(sourceSelector(document.querySelector('.a-block'))).to.be.equal('.a-block');
expect(sourceSelector(document.querySelector('#a-div-in-block'))).to.be.equal('.a-block #a-div-in-block');
Expand Down

0 comments on commit 522344a

Please sign in to comment.