Skip to content

Commit 94d65f2

Browse files
Merge pull request #11 from practical-computer/thomas/2025-12-12-submit-with-selected-menu-item-form-owner
`submit-with-selected-menu-item` can use a form attribute instead
2 parents c75152f + 4dc8f24 commit 94d65f2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@practical-computer/practical-views",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "The JS code for the view layer of the Practical Framework",
55
"exports": {
66
"./elements/auto-expire": "./src/elements/auto-expire.js",

src/elements/submit-with-selected-menu-item.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const menuItemSelectedEvent = async function(event) {
22
const dropdownElement = event.currentTarget
33
const menuElement = event.target
44
const value = event.detail.item.value
5+
const name = event.target.dataset.fieldName
56

6-
dropdownElement.form.elements[event.target.dataset.fieldName].value = value
7+
dropdownElement.form.elements[name].value = value
78
dropdownElement.form.requestSubmit()
89
}
910

@@ -19,11 +20,16 @@ class SubmitWithSelectedMenuItemElement extends HTMLElement {
1920
}
2021

2122
get form() {
22-
return this.querySelector(`:scope form`)
23+
if(this.hasAttribute(`form`)) {
24+
return document.getElementById(this.getAttribute(`form`))
25+
} else {
26+
return this.querySelector(`:scope form`)
27+
}
2328
}
24-
2529
}
2630

2731
if (!window.customElements.get('submit-with-selected-menu-item')) {
28-
window.customElements.define('submit-with-selected-menu-item', SubmitWithSelectedMenuItemElement);
32+
window.customElements.define('submit-with-selected-menu-item',
33+
SubmitWithSelectedMenuItemElement
34+
);
2935
}

0 commit comments

Comments
 (0)