From d9330cbab9d116050af8ad7fcbfdbfdd553257bf Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 31 Mar 2017 14:00:23 +0200 Subject: [PATCH] onblur event now works --- example.nim | 2 +- karax.nim | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example.nim b/example.nim index 83e2c58..6a03fac 100644 --- a/example.nim +++ b/example.nim @@ -38,7 +38,7 @@ proc editInput(i: int; d: cstring): VNode = entries[i] = val selectedEntry = -1 result = enterInput("todo-edit", d, onTodoChange) - #result.setOnfocuslost(proc (ev: Event; n: VNode) = selectedEntry = -1) + result.setOnfocuslost(proc (ev: Event; n: VNode) = selectedEntry = -1) proc createEntry(i: int; d: cstring; selected: bool): VNode = # implement caching: diff --git a/karax.nim b/karax.nim index 775ddf1..c050597 100644 --- a/karax.nim +++ b/karax.nim @@ -46,11 +46,12 @@ proc vnodeToDom(n: VNode): Element = let myn = n for e, h in items(n.events): proc wrapper(): proc (ev: Event) = + let hh = h result = proc (ev: Event) = assert myn != nil - h(ev, myn) + hh(ev, myn) result.addEventListener(toEventName[e], wrapper()) - if n.kind == VNodeKind.input: + if n.kind == VNodeKind.input and toFocus.isNil: toFocus = result proc same(n: VNode, e: Element): bool = @@ -148,7 +149,7 @@ proc dodraw() = proc redraw*() = # we buffer redraw requests: - when false: + when true: if drawTimeout != nil: clearTimeout(drawTimeout) drawTimeout = setTimeout(dodraw, 30)