| Author |
Message |
< Erlang Web mailing list ~ [Erlangweb-users] date type with optional date |
| Guest |
Posted: Wed Mar 31, 2010 10:41 am |
|
|
|
Guest
|
Hi,
I'm trying to use the date type(http://wiki.erlang-web.org/Wparts/BasicTypes/date) with an optional value for one of my input fields, but if I leave the field that has an optional value empty my validation fails. As long as I put a date in all fields the validation works! from my tracing:
(<0.3201.0>) call admin_utils:set_active(not_used,user_admin,admin_reports,[[]])
(<0.3201.0>) returned from admin_utils:set_active/4 -> {proceed,[[]]}
(<0.3201.0>) call admin_utils:validate({admin_report,create},user_admin,admin_reports,[[]])
(<0.3201.0>) call wtype_date:validate({[{description,"End date (YYYYMMDD)"},{format,"YYYYMMDD"}],"20100330"})
(<0.3201.0>) call wtype_date:convert_input("YYYYMMDD","20100330",[])
(<0.3201.0>) call wtype_date:convert_input("MMDD","0330",[{year,2010}])
(<0.3201.0>) call wtype_date:convert_input("DD","30",[{month,3},{year,2010}])
(<0.3201.0>) call wtype_date:convert_input([],[],[{day,30},{month,3},{year,2010}])
(<0.3201.0>) returned from wtype_date:convert_input/3 -> {2010,3,30}
(<0.3201.0>) returned from wtype_date:convert_input/3 -> {2010,3,30}
(<0.3201.0>) returned from wtype_date:convert_input/3 -> {2010,3,30}
(<0.3201.0>) returned from wtype_date:convert_input/3 -> {2010,3,30}
(<0.3201.0>) call wtype_date:check_min([{description,"End date (YYYYMMDD)"},{format,"YYYYMMDD"}],{2010,3,30})
(<0.3201.0>) returned from wtype_date:check_min/2 -> {ok,{2010,3,30}}
(<0.3201.0>) call wtype_date:check_max([{description,"End date (YYYYMMDD)"},{format,"YYYYMMDD"}],{2010,3,30})
(<0.3201.0>) returned from wtype_date:check_max/2 -> {ok,{2010,3,30}}
(<0.3201.0>) returned from wtype_date:validate/1 -> {ok,{2010,3,30}}
(<0.3201.0>) call wtype_date:validate({[{description,"Start date (YYYYMMDD)"},
{format,"YYYYMMDD"},
{optional,{2010,3,29}}],
[]})
(<0.3201.0>) call wtype_date:convert_input("YYYYMMDD",[],[])
(<0.3201.0>) returned from wtype_date:convert_input/3 -> {error,bad_format}
(<0.3201.0>) returned from wtype_date:validate/1 -> {error,
{bad_date_format,[]}}
(<0.3201.0>) returned from admin_utils:validate/4 -> {error,
{user_admin,
validate_error,
[admin_reports]}}
(<0.3201.0>) call wtype_date:get_date("YYYY-MM-DD","20100330")
(<0.3201.0>) returned from wtype_date:get_date/2 -> "20100330"
and my admin_report.hrl
-record(admin_report, {
start_date,
start_time,
end_date,
end_time}).
-record(admin_report_types,
{ start_date = {date, [ {description, "Start date (YYYYMMDD)"}
, {format, "YYYYMMDD"}
, {optional, {2010,03,29}}
]}
, start_time = {time, [ {description, "Start time (HHMMSS)"}
, {format, "HHMMSS"}
]}
, end_date = {date, [ {description, "End date (YYYYMMDD)"}
, {format, "YYYYMMDD"}
]}
, end_time = {time, [ {description, "End time (HHMMSS)"}
, {format, "HHMMSS"}
]}}).
any ideas?
Cheers,
Anders Karlsson
---------------------------------------------------
---------------------------------------------------
WE'VE CHANGED NAMES!
Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.
www.erlang-solutions.com
------------------------------------------------------------------------------
Download Intel® 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/
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Wed Mar 31, 2010 11:14 am |
|
|
|
Guest
|
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?
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
------------------------------------------------------------------------------
Download Intel® 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/
Post received from mailinglist |
|
|
| Back to top |
|
| Michal Ptaszek |
Posted: Sat Apr 03, 2010 7:10 pm |
|
|
|
User
Joined: 01 May 2008
Posts: 35
Location: Krakow
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|