[Checkins] SVN: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/js
made grouped event rendering include button events.
Paul Carduner
paulcarduner at gmail.com
Mon Jul 2 19:13:57 EDT 2007
Log message for revision 77314:
made grouped event rendering include button events.
Changed:
U Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.txt
U Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsevent.py
-=-
Modified: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.txt
===================================================================
--- Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.txt 2007-07-02 20:30:16 UTC (rev 77313)
+++ Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.txt 2007-07-02 23:13:57 UTC (rev 77314)
@@ -28,11 +28,9 @@
z3c.form. The difference comes with the actions. We will create a
form that provides these buttons with javascript actions.
- >>> from z3c.form import button
+ >>> from z3c.form import button, form
>>> from z3c.form import interfaces
- >>> class Form(object):
- ... zope.interface.implements(
- ... interfaces.IButtonForm, interfaces.IHandlerForm)
+ >>> class Form(form.AddForm):
... buttons = button.Buttons(IButtons)
... prefix = 'form'
...
@@ -55,13 +53,13 @@
that we first need a request and a form instance:
>>> request = TestRequest()
- >>> form = Form()
+ >>> addform = Form(None, request)
Action managers are instantiated using the form, request, and
context/content. A special button-action-manager implementation is avaialble
in the ``z3c.form.button`` package:
- >>> actions = button.ButtonActions(form, request, None)
+ >>> actions = button.ButtonActions(addform, request, None)
>>> actions.update()
Once the action manager is updated, the buttons should be available as
@@ -113,3 +111,14 @@
name="form.buttons.cancel" class="buttonWidget"
value="Cancel" />
<script type="text/javascript">$("#form-buttons-cancel").bind("dblclick", function(){alert("You Double Clicked the Cancel Button!");});</script>
+
+Another way to render the events is completely separate from the
+buttons themselves.
+
+ >>> request = TestRequest()
+ >>> addform = Form(None, request)
+ >>> addform.update()
+ >>> zope.component.provideAdapter(jsevent.JSFormEventsRenderer)
+ >>> print jsinterfaces.IJSFormEventsRenderer(addform).render()
+ $("#form-buttons-apply").bind("click", function(){alert("You Clicked the Apply Button!");});
+ $("#form-buttons-cancel").bind("dblclick", function(){alert("You Double Clicked the Cancel Button!");});
Modified: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsevent.py
===================================================================
--- Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsevent.py 2007-07-02 20:30:16 UTC (rev 77313)
+++ Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsevent.py 2007-07-02 23:13:57 UTC (rev 77314)
@@ -122,6 +122,17 @@
# XXX: is this a safe way to get ids?
id = self.form.widgets[field.__name__].id
result += renderer.render(handler, id, self.form) + '\n'
+ #render events attached to buttons
+ if hasattr(self.form, 'buttons'):
+ for field in self.form.buttons.values():
+ handler = self.form.jshandlers.getHandler(field)
+ if handler is not None:
+ renderer = zope.component.getMultiAdapter((handler.event, self.request),
+ interfaces.IJSEventRenderer)
+ # XXX: is this a safe way to get ids?
+ id = self.form.actions[field.__name__].id
+ result += renderer.render(handler, id, self.form) + '\n'
+
return result
More information about the Checkins
mailing list