diff --git a/examples/toychat.nim b/examples/toychat.nim index 600998c..11ec7a4 100644 --- a/examples/toychat.nim +++ b/examples/toychat.nim @@ -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 = diff --git a/karax.nimble b/karax.nimble index 9e29495..7d95304 100644 --- a/karax.nimble +++ b/karax.nimble @@ -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" diff --git a/karax/karax.nim b/karax/karax.nim index c32e969..5ec4f5d 100644 --- a/karax/karax.nim +++ b/karax/karax.nim @@ -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)) diff --git a/readme.rst b/readme.rst index 6099bd8..f515667 100644 --- a/readme.rst +++ b/readme.rst @@ -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, "")