diff --git a/modules/dom.js b/modules/dom.js index 26eef94..16a030d 100644 --- a/modules/dom.js +++ b/modules/dom.js @@ -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')}`; diff --git a/test/unit/dom.sourceSelector.test.html b/test/unit/dom.sourceSelector.test.html index 6b3ab3e..5c38156 100644 --- a/test/unit/dom.sourceSelector.test.html +++ b/test/unit/dom.sourceSelector.test.html @@ -18,6 +18,9 @@ +
+ +
@@ -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');