From bf28a4443960f7808f293a5bc6fce719a0771d18 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 20 Nov 2017 14:04:34 +0100 Subject: [PATCH] fixes issues in the new examples --- examples/login.nim | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/examples/login.nim b/examples/login.nim index 4980269..6cc38b1 100644 --- a/examples/login.nim +++ b/examples/login.nim @@ -8,25 +8,21 @@ proc loginField(desc, field, class: kstring; result = buildHtml(tdiv): label(`for` = field): text desc - input(class = class, id = field, onkeyuplater = validator(field)) - -const - login = kstring"login" # a const to prevent typos - -proc validateNotEmpty(field: kstring): proc () = - result = proc () = - let x = getVNodeById(field) - if x.text.isNil or x.text == "": - errors.setError(login, field & " must not be empty") - else: - errors.setError(login, "") - + input(class = class, id = field, onchange = validator(field)) # some consts in order to prevent typos: const username = kstring"username" password = kstring"password" +proc validateNotEmpty(field: kstring): proc () = + result = proc () = + let x = getVNodeById(field) + if x.text.isNil or x.text == "": + errors.setError(field, field & " must not be empty") + else: + errors.setError(field, "") + var loggedIn: bool proc loginDialog(): VNode = @@ -37,12 +33,15 @@ proc loginDialog(): VNode = button(onclick = () => (loggedIn = true), disabled = errors.disableOnError()): text "Login" p: - text errors.getError(login) + text errors.getError(username) + p: + text errors.getError(password) else: p: text "You are now logged in." -setError login, username & " must not be empty" +setError username, username & " must not be empty" +setError password, password & " must not be empty" when not declared(toychat): setRenderer loginDialog