Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 35f8341

Browse files
committed
Ensure form submit and input values are handled correctly.
1 parent 50af200 commit 35f8341

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

polyplug.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const polyplug = function() {
8787
if (Object.keys(attrs).length > 0) {
8888
obj.attributes = attrs;
8989
}
90-
if (obj.tagName === "textarea") {
90+
if (node.value) {
9191
obj.value = node.value;
9292
}
9393
const childNodes = node.childNodes;
@@ -133,7 +133,7 @@ const polyplug = function() {
133133
node.setAttribute(attribute[0], attribute[1]);
134134
})
135135
}
136-
if (obj.tagName === "textarea") {
136+
if (obj.value) {
137137
node.value = obj.value;
138138
}
139139
break;
@@ -362,6 +362,8 @@ const polyplug = function() {
362362
});
363363
const send = new CustomEvent("polyplugSend", {detail: detail});
364364
document.dispatchEvent(send);
365+
e.preventDefault();
366+
return false;
365367
}
366368
REGISTERED_EVENTS[listener] = eventHandler;
367369
elements.forEach(function(element) {

polyplug.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,7 @@ def __init__(self, **kwargs):
367367
super().__init__(**kwargs)
368368
self.tagName = kwargs["tagName"]
369369
self.attributes = Attributes(kwargs.get("attributes", {}))
370-
if self.tagName == "textarea":
371-
# The textarea doesn't have children. Only a text value.
372-
self.value = kwargs.get("value", "")
370+
self.value = kwargs.get("value")
373371

374372
def add_child(self, child):
375373
"""
@@ -458,8 +456,9 @@ def as_dict(self):
458456
}
459457
if self.attributes:
460458
result["attributes"] = self.attributes
461-
if self.tagName == "textarea":
462-
result["value"] = self.value
459+
value = getattr(self, "value", None)
460+
if value:
461+
result["value"] = value
463462
return result
464463

465464
def find(self, selector):

tests/test_polyplug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def test_wrapper():
7171
"attributes": {
7272
"type": "text",
7373
"name": "testInput",
74-
"value": "test",
7574
},
75+
"value": "test",
7676
"childNodes": [],
7777
},
7878
{

0 commit comments

Comments
 (0)