The validation function returns {error, [ErrorMessage*s*]} - correct if u 
have only one error
It returns {error, [Error1, Error2, ..., ErrorN]} in general


validation_tests() -> [
{fun()-> false end, <<"email">>},
{fun()-> false end, <<"password">>},
].

case ....:save() of
{ok, _} ->
{error, E} -> {render_other, [{action,"show"}], [{errors, E}]} % or {json, 
[{errors, E}]}
end


On frontend don't forget to check name against array of errors, so this 
will not work if we consider given above case {% if email == errors %} 
has-error {% endif %}

I use custom tag for this {%if errors|has:"email"%}has-error{%endif%}

has(undefined,_)->false;
has([],_)->false;
has(Errors,Key)->has(Errors,Key,false).

has(_,_,true)->true;
has([],_,Res)->Res;
has([H|T],Key,_)->has(T,Key,H=:=Key).



On Monday, October 20, 2014 10:42:55 AM UTC+4, Alex V wrote:
>
>
>
> Hi everyone.
>
> Saw similar, but unanswered questions.
>
> When returning json from a controller, the browser often gets arrays 
> instead of strings (even from tutorial examples, "greeting-N" always 
> becomes an array) and vice versa. How do you control this behavior?
>

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/1b032c74-3c8d-4563-90b6-aa63961bfe64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to