formjs enhancements and calculator demo

I recently (as in yesterday on the plane) finished some final enhancements to the field event linking framework of formjs. I also created a calculator demo which mimics exactly the demo that Stephan Richter wrote with z3c.form except that all calculations are done on the client side using Javascript. The other important news is that I have now moved the code out of my sandbox and into the root svn.zope.org directory under z3c.formjs and z3c.formjsdemo.

The following is an example of how fields have JavaScript events attached to them. This is taken directly from the doctests which you can read here: jsevent.txt and jsbutton.txt.


  >>> class IPerson(zope.interface.Interface):
  ...
  ...     name = zope.schema.TextLine(
  ...         title=u'Name',
  ...         required=True)
  ...
  ...     gender = zope.schema.Choice(
  ...         title=u'Gender',
  ...         values=('male', 'female'),
  ...         required=False)
  ...
  ...     age = zope.schema.Int(
  ...         title=u'Age',
  ...         description=u"The person's age.",
  ...         min=0,
  ...         default=20,
  ...         required=False)

  >>> class PersonEditForm(form.AddForm):
  ...
  ...     fields = field.Fields(IPerson)
  ...
  ...     @jsevent.handler(fields['age'])
  ...     def ageClickEvent(self, id):
  ...         return 'alert("The Age was Clicked!");'
  ...
  ...     @jsevent.handler(fields['gender'], event=jsevent.CHANGE)
  ...     def genderChangeEvent(self, id):
  ...         return 'alert("The Gender was Changed!");'

In a page template file you might write the following to render the form and all the event attachment javascript:


About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 76 other followers

%d bloggers like this: