6.24.2007

New Blog Coming Soon

So I got tired of the blogger thing and decided that since I was upgrading my current web hosting solution, I might as well setup wordpress on my own box and use that instead. So check it out at

blog.carduner.net

6.23.2007

z3c.formjs 0.1 coming soon

After a few weeks of fruitful and not so fruitful work sessions, I am slowly approaching the benchmark for a 0.1 release of z3c.formjs. So what will be provided in the 0.1 release?

  • Easy to use JavaScript button widget built right into z3c.form
  • Easy JavaScript event handler attachment to form widgets
  • A demo of the above two features.
Currently the JavaScript buttons work and the generic JavaScript event handlers for any widget are almost ready - it can be done, it's just not easy. I also now have a demo of button usage. In fact, here is a code snippet from that demo:
import zope.interface
from z3c.form import form, button
from z3c.formui import layout
from z3c.formjs import jsbutton

class IButtons(zope.interface.Interface):
show = jsbutton.JSButton(title=u'Show Code')
hide = jsbutton.JSButton(title=u'Hide Code')

class ButtonForm(layout.FormLayoutSupport, form.EditForm):

buttons = button.Buttons(IButtons)

@jsbutton.handler(IButtons['show'])
def handleShow(self, id):
return '$("#code").slideDown()'

@jsbutton.handler(IButtons['hide'])
def handleHide(self, id):
return '$("#code").slideUp()'

As you can see, creating JavaScript buttons is as simple as creating regular buttons. Under the hood there is some rather complicated code that makes heavy use of Zope's component architecture to allow for maximum customization and (drum roll) js library agnosticism. That's right - you will be able to customize z3c.formjs to work with any JavaScript library you want. By default though, JavaScript renderers for jQuery are provided.

What about future releases?

I'm looking at some pretty nifty possible features for doing common - yet tedious JavaScript tasks. Here is a scenario I plan to make simple to do. Let's say you have an address form which includes fields for city and state. If the user enters in San Francisco for the city and New York for the state, that shouldn't validate. The trick is connecting the city and state fields so that a modification to the state updates the validation of the city. In a form this might look like:
@jsevent.handler(fields['state'], event=jsevent.CHANGED)
def handleStateChange(self, id):
return jsevent.updateWidgetFor(self.fields['city']).render()

So this would generate JavaScript code (using whatever js framework renderers have been written for) such that when the state field iss changed there would be an HTTP Post sent to the server with the data for the state. The post will probably be sent to a url like context/@@form.html/widgets/city/get?state=WA. Then the city widget would be replaced with the HTTP Post returns - presumably a widget with a modified js validator.

But these are just thoughts at this point and the API is very likely to change as problems and their solutions are discovered.