- Don't invent a new Javascript library
- Don't force the developer to learn Javascript
Don't invent something new, don't code Javascript
I've been experimenting with both in the context of Plone. Here is how it breaks down. Mochikit might be better if you are writing alot of Javascript. This is not however the goal of my experimentation. I like auto generated forms and widgets and I'd rather just make those come alive than. Prototype and family are already used in this capacity in Rails so there is experience in what makes a logical binding between the server side and the client.
If we are not writing Javascript then what do we write? Well, Plone UI people know TAL and a bit of Python so I thought I'd aim for that. Introduce Bling, some helper code than can be used in TAL to spit out the Javascript you need.
I only wrote this yesterday so its a little halfed backed but here is how it might work. This will create a "checkedField", something that validates server-side on change using AJAX and then writes to or clears an error div on the client.
<label for="foo">FOO</label> <input type="text" id="foo"
name="foo"\/>
<div tal:replace="structure python:ajax.checkedField(
here.portal_url() + '/dval', 'foo', error='error')"/>
which might generate something like
<label for="foo">FOO</label> <input id="foo" name="foo" type="text">
<script type="text/javascript">
new Form.Element.EventObserver($('foo'),
function(element, value) { new Ajax.Updater({success:
$('error'),failure:
$('error')},
'http://site/bling/dval', {
onFailure:function(request){
new Effect.Appear($('error'),{}); Fie\ld.activate('foo');},
parameters:Form.Element.serialize($('foo')),
onSuccess:function(request){new Effect.DropOut($('error'),{})},
asynchronous:true,insertion:null,method:'post\'} ) })
Fun Prototype callouts you didn't have to write or think about. Most of the kinds of tags you'd expect in rails are here already and I've added a few more to show how something like Plone could carry a standard array of reuable behaviors and visual effects.
Next we change something like Archetypes that already has per-field validation logic and vocabulary support and allow for things like auto-completion and validition from the widget layer with out change.
To show how simple this is I've written it into a product already. This will install the proper scripts into the resource registries in Plone. Just create a new site, install this product and play with the test.pt template in its skin path. The methods of interest are in Bling/ajax.py
To get the bundle you need darcs:
darcs get http://darcs.objectrealms.net/repos/Bling
or you can just look at the repo at
http://darcs.objectrealms.net/darcsweb.cgi/bling