I haven't actually hooked up the javascript validation yet. But it's
a simple task.
Basically I created a class called a "Control" (the name isn't right,
but it's the going title), the Control has two aspects, one is Django
side and one is Javascript side. In the Javascript you declare a
server-side funciton like this:
function Control(element)
{
AjaxControlAspect(this, element); //Makes this object an ajax control.
// "element" binds this control to an HTML element, e.g. a DIV
get_report = remoteFunction(this, "get_report");
// <javascript_method_name> = remoteFunction(this, <django_method_name>);
function set_report(what)
{
alert("Report:" + what);
}
}
On the Django side you do:
class Control(AjaxControl):
@exposed
def get_report(request, argument):
return JavascriptResponse("set_report",
"Here is the argument sent: %r" % argument)
That JavascriptResponse actually calls the function "set_report" on
the javascript control.
So if you did, javascript side:
o = Control(some_div);
o.get_report("Hello")
It will give you an alert box saying: Here is the argument sent: 'Hello'
Okay, so you have that bridge, it's basically an RPC mechanism using
JSON. But here's where it gets nifty:
Instead of doing method = remoteFunction(this, "method"), you can also do:
edit_object = remoteManipulator(this, "edit_object");
And then you can call control.edit_object(<form or form element>,
object_id); It will send the contents of that form through to a
control set up like this:
class Control(AjaxControl):
class EditManipulator(Manipulator):
def __init__(self):
self.fields = (
forms.SelectField("weekday", choices=Weekly.WEEKDAYS),
forms.TextField("something"),
)
@form(EditManipulator)
def edit_object(self, form_data, id):
# apply the form_data to the object with pk = id
Anyhow, I'm sure that's terribly confusing. Thusly, I am trying to
simplify it, and work it into something manageable. Then I can
release it. Hopefully I can combine this with a simplified
Manipulator system and we're off.
On 7/17/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Brantley Harris wrote:
> > Is there any discussion on the fate of manipulators? I've done a lot
> > on my own to make it more managable (including making a very cool
> > 'remote manipulator that executes via ajax'), so I'd like to see where
> > this is all going, a plan or what not.
>
> Whoa! I was just thinking about how to write an ajax remote
> manipulator -- how did you do it? Can you specify django validators
> that insert javascript validation to the form's page? Do you have a
> demo or code anywhere for this?
>
> Brendan
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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/django-developers
-~----------~----~----~----~------~----~------~--~---