added a getInputText API, cleaner and more robust than the .text attribute which is often updated too late in event handlers after a redraw
This commit is contained in:
parent
24a037ad19
commit
9a627985d0
4 changed files with 8 additions and 4 deletions
|
|
@ -11,7 +11,7 @@ var allMessages: seq[TextMessage] = @[]
|
|||
|
||||
proc doSendMessage() =
|
||||
let inputField = getVNodeById(message)
|
||||
allMessages.add(TextMessage(name: "you", content: inputField.text))
|
||||
allMessages.add(TextMessage(name: "you", content: inputField.getInputText))
|
||||
inputField.setInputText ""
|
||||
|
||||
proc main(): VNode =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "1.1.3"
|
||||
version = "1.2.0"
|
||||
author = "Andreas Rumpf"
|
||||
description = "Karax is a framework for developing single page applications in Nim."
|
||||
license = "MIT"
|
||||
|
|
|
|||
|
|
@ -809,6 +809,10 @@ proc setInputText*(n: VNode; s: cstring) =
|
|||
n.text = s
|
||||
if n.dom != nil: n.dom.value = s
|
||||
|
||||
proc getInputText*(n: VNode): cstring =
|
||||
if n.dom != nil:
|
||||
result = n.dom.value
|
||||
|
||||
proc toChecked*(checked: bool): cstring =
|
||||
(if checked: cstring"checked" else: cstring(nil))
|
||||
|
||||
|
|
|
|||
|
|
@ -250,8 +250,8 @@ captures the ``field`` parameter:
|
|||
|
||||
proc validateNotEmpty(field: kstring): proc () =
|
||||
result = proc () =
|
||||
let x = getVNodeById(field)
|
||||
if x.text.isNil or x.text == "":
|
||||
let x = getVNodeById(field).getInputText
|
||||
if x.isNil or x == "":
|
||||
errors.setError(field, field & " must not be empty")
|
||||
else:
|
||||
errors.setError(field, "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue