Skip to content

Commit

Permalink
Fixing up the form.rules/duplication predicate field copying in valid…
Browse files Browse the repository at this point in the history
…_fields.

Also adds a test.
  • Loading branch information
archaelus committed Aug 22, 2008
1 parent 1c4cf52 commit 6855fea
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/erlydtl/forms/form.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ rules(#form{fields=Fields, rules=FormRules}) ->

valid_fields(F, Result, Data) ->
Simple = simple_copy(Result, Data),
Complex = [ case proplists:get_value(Field, Result) of
[] -> [{Fi, proplists:get_value(Field, Data)} || Fi <- Fields];
undefined -> []
% on a {Name, {duplication, ...} rule, put {Name, Field} into
Complex = [ case {proplists:get_value(Field, Result),
proplists:get_value(Field, Simple)} of
{[], Value} ->
{Rule, Value};
_ ->
[]
end
|| {Rule, [{duplication, [Field|Fields]}]} <- form_rules(F),
proplists:get_value(Rule, Result) =:= []],
lists:flatten([Simple, Complex]).
%% handle faux fields.

%%====================================================================
%% Internal functions
Expand Down Expand Up @@ -184,10 +187,21 @@ valid_fields_test() ->
{"other", baz},
{"random", baz}])),
?assertMatch([{"valid", foo},
{"other", foo}],
{"Foo", foo}],
valid_fields(#form{rules=[{"Foo", [{duplication, ["valid", "other"]}]}]},
[{"valid", []},
{"Foo", []}],
[{"valid", foo},
{"invalid", bar},
{"other", baz},
{"random", baz}])),
?assertMatch([{"valid", foo},
{"other", baz},
{"Foo", foo}],
valid_fields(#form{rules=[{"Foo", [{duplication, ["valid", "other"]}]}]},
[{"valid", []},
{"other", []},
{"Foo", []}],
[{"valid", foo},
{"invalid", bar},
{"other", baz},
Expand Down

0 comments on commit 6855fea

Please sign in to comment.