Skip to content

Commit d8a68bf

Browse files
STRd6claude
andcommitted
guard non-function value bindings
bindValue invoked the bound property as a setter via an optional call, which only guards null/undefined. A plain value (e.g. a number) threw "is not a function" on input. Cache the binding and call it only when it's a function, so plain values degrade to one-way (display + read). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5f5efb7 commit d8a68bf

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

source/index.civet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ bindValue := (element: JadeletElement, value: JadeletAttribute, context: Context
160160
// inconsistencies.
161161
if value and typeof value is "object"
162162
element.oninput = element.onchange = ->
163-
context[value.bind]? element.value
163+
setter := context[value.bind]
164+
if typeof setter is 'function'
165+
setter.call context, element.value
164166
return
165167

166168
bindObservable element, value, context, (newValue: string) ->

test/input.civet

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,18 @@ describe "input", ->
3030

3131
el := T()
3232
assert.equal el.value, "hello"
33+
34+
it "should accept a non-function (plain value) binding without throwing on input", ->
35+
model :=
36+
value: 5
37+
38+
input := template(model)
39+
40+
// initial value reflects the plain number
41+
assert.equal input.value, "5"
42+
43+
// editing must not attempt to call the non-function binding
44+
input.value = "7"
45+
input.oninput()
46+
47+
assert.equal input.value, "7"

0 commit comments

Comments
 (0)