fixes issues in the new examples
This commit is contained in:
parent
fb604321f3
commit
bf28a44439
1 changed files with 14 additions and 15 deletions
|
|
@ -8,25 +8,21 @@ proc loginField(desc, field, class: kstring;
|
||||||
result = buildHtml(tdiv):
|
result = buildHtml(tdiv):
|
||||||
label(`for` = field):
|
label(`for` = field):
|
||||||
text desc
|
text desc
|
||||||
input(class = class, id = field, onkeyuplater = validator(field))
|
input(class = class, id = field, onchange = 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, "")
|
|
||||||
|
|
||||||
|
|
||||||
# some consts in order to prevent typos:
|
# some consts in order to prevent typos:
|
||||||
const
|
const
|
||||||
username = kstring"username"
|
username = kstring"username"
|
||||||
password = kstring"password"
|
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
|
var loggedIn: bool
|
||||||
|
|
||||||
proc loginDialog(): VNode =
|
proc loginDialog(): VNode =
|
||||||
|
|
@ -37,12 +33,15 @@ proc loginDialog(): VNode =
|
||||||
button(onclick = () => (loggedIn = true), disabled = errors.disableOnError()):
|
button(onclick = () => (loggedIn = true), disabled = errors.disableOnError()):
|
||||||
text "Login"
|
text "Login"
|
||||||
p:
|
p:
|
||||||
text errors.getError(login)
|
text errors.getError(username)
|
||||||
|
p:
|
||||||
|
text errors.getError(password)
|
||||||
else:
|
else:
|
||||||
p:
|
p:
|
||||||
text "You are now logged in."
|
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):
|
when not declared(toychat):
|
||||||
setRenderer loginDialog
|
setRenderer loginDialog
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue