diff --git a/plugins/bindable.js b/plugins/bindable.js
index efcf938e..b3424084 100644
--- a/plugins/bindable.js
+++ b/plugins/bindable.js
@@ -9,7 +9,7 @@ function transform({ node, environment }) {
const object = node.attributes.bind.object ?? {}
const property = node.attributes.bind.property
if (node.type === 'textarea') {
- node.children = [object[property]]
+ node.children = [object[property] ?? '']
} else if (node.type === 'input' && node.attributes.type === 'checkbox') {
node.attributes.checked = object[property]
} else {
diff --git a/tests/src/TwoWayBindings.njs b/tests/src/TwoWayBindings.njs
index cc73b6b7..64a77596 100644
--- a/tests/src/TwoWayBindings.njs
+++ b/tests/src/TwoWayBindings.njs
@@ -97,6 +97,8 @@ class TwoWayBindings extends Nullstack {
+
+
diff --git a/tests/src/TwoWayBindings.test.js b/tests/src/TwoWayBindings.test.js
index 80310fb8..885486f9 100644
--- a/tests/src/TwoWayBindings.test.js
+++ b/tests/src/TwoWayBindings.test.js
@@ -69,8 +69,13 @@ describe('TwoWayBindings', () => {
expect(value).toMatch('a')
})
- test('binding to undefined sets the value to an empty string', async () => {
- const value = await page.$eval('[data-undeclared]', (element) => element.value)
+ test('binding inputs to undefined sets the value to an empty string', async () => {
+ const value = await page.$eval('input[data-undeclared]', (element) => element.value)
+ expect(value).toMatch('')
+ })
+
+ test('binding textarea to undefined sets the value to an empty string', async () => {
+ const value = await page.$eval('textarea[data-undeclared]', (element) => element.value)
expect(value).toMatch('')
})
@@ -225,8 +230,13 @@ describe('TwoWayBindings', () => {
expect(element).toBeTruthy()
})
- test('binding to nested undefined sets the value to an empty string', async () => {
- const value = await page.$eval('[data-undeclared-nested]', (element) => element.value)
+ test('binding inputs to nested undefined sets the value to an empty string', async () => {
+ const value = await page.$eval('input[data-undeclared-nested]', (element) => element.value)
+ expect(value).toMatch('')
+ })
+
+ test('binding textareas to nested undefined sets the value to an empty string', async () => {
+ const value = await page.$eval('textarea[data-undeclared-nested]', (element) => element.value)
expect(value).toMatch('')
})