Hi,

Wiadomość napisana w dniu 2010-03-31, o godz. 13:14, przez Roberto Aloi:

Hi all,

(<0.3201.0>) call wtype_date:validate({[{description,"Start date (YYYYMMDD)"},
 {format,"YYYYMMDD"},
 {optional,{2010,3,29}}],
[]})

The validate function here is called with [] since the user didn't set
any value in the form.
In wtype_date.erl, the validate function is expecting the atom
"undefined" instead, to trigger the search of the optional value.

validate({Types, undefined}) ->
   case wpart_valid:is_private(Types) of
        true ->
            {ok, undefined};
       false ->
           case lists:keysearch(optional, 1, Types) of
                {value, {optional, Default}} ->
                   {ok, Default};
                _ ->
                   {error, {empty_input, undefined}}
           end
   end;

The wype_date.erl should match:

validate({Types, []}) ->

Or am I missing something?

Well, it depends on what would you like to achieve.

In Erlang Web "optional" attribute is activated only when there is no corresponding field on the form (HTML), thus no value is passed/sent to the server. When no value is entered into the form, the field is set to "" and the first validate function clause does not match.

The more I think about it, the more I am convinced to your way of thinking (or just to keep both behaviours).


Roberto Aloi
--
University of Kent - Erlang Solutions Ltd.
Twitter: @prof3ta
Blog: http://aloiroberto.wordpress.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com

Cheers,
Michal Ptaszek
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Erlangweb-users mailing list
Erlangweb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlangweb-users
http://www.erlang-web.org/

Reply via email to