> I'm using jquery to submit a form via AJAX.  The tg_errors dictionary
> that holds the validation errors doesn't come back from the server.
>
> I think this is because turbogears.validators.Invalid instances can't
> be dumped by simplejson.

This is correct.

> How do I redraw the form to show the errors?  I can daydream up some
> boring and labor-intensive solutions, but I don't like them.

I'm using tg1 and you can just add the following into your set of
jsonification rules, conventionally in json.py:

@jsonify.when('isinstance(obj, Invalid)')
def jsonify_tg_errors(obj):
    result = { }
    result['msg'] = obj.msg
    result['value'] = str(obj.value)
    error_list = getattr( obj, 'error_list', None )
    error_dict = getattr( obj, 'error_dict', None )
    if error_list is not None:
        result['error_list'] = str(error_list)
    if error_dict is not None:
        result['error_dict'] = str(error_dict)
    return result

I bet it's not perfect but works for me pretty well. I don't know
about tg2 though.

HTH,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to