Everyone knows.  Client-side validation is often just a first line of
defense for UIX purposes.  Doing client-side and server-side
validation requires writing/hooking up the same validator twice.  The
code in question is hardly unique.  Neither is the signature nor flow
control of the client-side form loaders, validators, or processors.
RY.

An AJAX form that might get loaded dynamically then has to validate
itself, ask the server if all went well, and maybe reload errors and
submit again, rinsing and repeating before re-hiding the div/iframe.
The load has to either accept a second parameter or hit another URL.
Flow control gets into the view or bloats the URL's.  Either way, the
server needs to know the difference between the different requests.

In place of a hodge-podge of user code that can so frequently be
boiled down to:

1.  Load form (if form was in an iframe, reveal it.)
2.  Validate user input
3.  Submit to server and ask for errors
4.  If errors, ask for the errors and display them
5.  All clear.  Present feedback to user

What I would propose is an extended form object on the server that can
do the following:

1.  Prior to cleaning, determine which type of request is being asked
for
2.  Provide context to the template to say whether to reload with the
javascript or just the AJAX relevant fragment.  Corresponding template
tags like {% subTemplate %} to avoid trivial template nesting.
3.  Ability to pass other data parameters back to the AJAX call in
addition to the html string that needs display on the client.
4.  Outputs HTML that is logically and uniquely identified so that
AJAX processing code can predictably and without-wrist-breaking update
client-side error messages (usually overwriting the server-side
feedback).
5.  Guts.  No system like this is useful if it doesn't have obscure
options for writing the form's nth element inside a specific canvas
tag etc.


I have the following gripes against my own solutions:

0.  HAND-WRITING FORM HTML OR USING SUB-FORM TEMPLATE TAGS SO MY AJAX
CODE KNOWS WHAT TO VALIDATE AND WHERE TO PUT SERVER-SIDE FEEDBACK.  =)
1.  Occasionally my js code becomes template-aware, telling the server
exactly what to load.  A template naming scheme helps, but in the end
my code is broken into too many pieces.
2.  I also do event management where the ultimate processing of a form
calls a method on the main page (the event  callback) which might
cause other AJAX elements to update (user login for instance).  Good
naming schemes help, but once again I'm putting code in seven places
to do one (potentially many, but usually less than seven) things.


-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to