Slide 60: Overview of Nitrogen Validation (#is_required{})
wf:wire/3
associates the validation with its first argument, here a specific element labeled "submit", and specifies the validation target according to element label. The wf:wire/3
calls occur before the definition of the elements.
Slide 61: Overview of Nitrogen Validation (#custom{} and #js_custom{})
#custom{}
for the server, #js_custom{}
for the client. My experience in this exercise is an uninteresting series of typos, syntax errors, and misremembered names. The biggest take away is that Internal server error
usually means I've called an undefined function - specifically, misremembered the name of a system function. To reorient myself after my absence, here's the full login.erl code:
%% -*- mode: nitrogen -*-
-module (login).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-include("records.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "Hello from login.erl!".
body() ->
wf:wire(submit, username, #validate { validators = [
#is_required { text = "Required" }
]}),
wf:wire(submit, password, #validate { validators = [
#is_required { text = "Required" },
#custom {
text = "Invalid password.",
function = fun(_, Value) -> Value == "password" end
}
]}),
#panel { style="margin: 50px;", body=[
#flash {},
#label { text="Username" },
#textbox { id=username, next=password },
#br {},
#label { text="Password" },
#password { id=password, next=submit },
#br {},
#button { text="Login", id=submit, postback=login }
]}.
event(login) ->
wf:role(managers, true),
wf:redirect_from_login("/").
Slide 66: A Comet Counter
How boring: I typed it correctly, and it worked as described :-).
Slide 67: Comet Pools
Functions wf:comet/2
and wf:send/2
. Vague: does a function have to execute a receive to receive these messages, or does the message appear as the argument to the function?
Slide 68: Comet Pool Scope
Normally, scoped by page and user, with a refresh replacing old scope with new one. With wf:comet_global/2
and wf:send_global/2
, they live for the life of the server.
Slide 69: The Simplest Chatroom Ever Constructed
Answer revealed! Functions do have to invoke receive
to get pool messages. To observe the semi-obvious: the nitrogen console
process must be in the foreground (e.g., running and attached to the terminal) for dev page newpage
to function correctly.
No comments:
Post a Comment