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() =
|
proc doSendMessage() =
|
||||||
let inputField = getVNodeById(message)
|
let inputField = getVNodeById(message)
|
||||||
allMessages.add(TextMessage(name: "you", content: inputField.text))
|
allMessages.add(TextMessage(name: "you", content: inputField.getInputText))
|
||||||
inputField.setInputText ""
|
inputField.setInputText ""
|
||||||
|
|
||||||
proc main(): VNode =
|
proc main(): VNode =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.1.3"
|
version = "1.2.0"
|
||||||
author = "Andreas Rumpf"
|
author = "Andreas Rumpf"
|
||||||
description = "Karax is a framework for developing single page applications in Nim."
|
description = "Karax is a framework for developing single page applications in Nim."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -809,6 +809,10 @@ proc setInputText*(n: VNode; s: cstring) =
|
||||||
n.text = s
|
n.text = s
|
||||||
if n.dom != nil: n.dom.value = 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 =
|
proc toChecked*(checked: bool): cstring =
|
||||||
(if checked: cstring"checked" else: cstring(nil))
|
(if checked: cstring"checked" else: cstring(nil))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,8 @@ captures the ``field`` parameter:
|
||||||
|
|
||||||
proc validateNotEmpty(field: kstring): proc () =
|
proc validateNotEmpty(field: kstring): proc () =
|
||||||
result = proc () =
|
result = proc () =
|
||||||
let x = getVNodeById(field)
|
let x = getVNodeById(field).getInputText
|
||||||
if x.text.isNil or x.text == "":
|
if x.isNil or x == "":
|
||||||
errors.setError(field, field & " must not be empty")
|
errors.setError(field, field & " must not be empty")
|
||||||
else:
|
else:
|
||||||
errors.setError(field, "")
|
errors.setError(field, "")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue