Re: [Erlangweb-users] "checked" radio buttons by default on forms
Brought to you by:
etcerlangweb,
paulgray
|
From: Michal Z. <mic...@er...> - 2008-11-17 00:08:11
|
hi,
first thing is that example was very simple application to show general idea about Erlang Web.
To achieve functionality You are talking about we need to clarify several issues. 'wparts' are responsible for building HTML. 'optional' field is checked -- but in 'wtypes' during validation.
If You would like to build form with default values already in input fields, we need new function which prepares form e.g. before_add and there is place to set
wpart:fset(__edit, {name_of_field_in form, default_value}). It will require new entry in dispatcher file.
But going back to exact problem. {optional, ...} works as You wish. When empty field is submitted validator checks if there is declared {optional, default_value}. If it is, instead of {error, undefined} -- {ok, default_value} is passed to controller (not directly). This value will be set to DB. On the other hand if this cannot be specified by default (lets say Age) do not set {optional, ..} and on error go again to form with wrong fields (here empty) surrounded with red frame (any frame - ccs). Of course previous values set by user should be retrieved (it is mostly done by validate_tool) and here we use Default variable in wparts.
One of reasons why this way of handling default values is useful is that, it is hard to escape some of the HTML tags. And it gives more flexibility.
Sorry for bad example -- I will try to fix it shortly. More interesting stuff about CRUD functionality You can find in tutorial on erlang-web.org. Some more complicated examples to intorduce Erlang Web will be published soon.
br
Michal Zajda
|