[Zope3-Users] clearing grouped widgets in z3c.form

John john at saponara.net
Thu Feb 28 21:26:09 EST 2008


In modifying the formdemo/addressbook example to use groups, I found 
that fields in groups are not cleared to their default values when the 
Done or Delete button is pressed in the editform, resulting in an 
addform with values from the previous editform.  Fields that are not in 
groups are cleared (as in the original example, which had no groups); 
only fields in groups have this problem.  How can I fix this?  And more 
generally, how are widgets cleared?

Relevant code is attached.  The editform class is below.

thanks!

-------
class CarEditForm(group.GroupForm,form.EditForm):
  form.extends(group.GroupForm,form.EditForm)
  noChangesMessage = None
  fields = field.Fields(ICar).select('nPassengers')
  groups=(carGroup1,)
  prefix = 'car.edit.'
  @button.buttonAndHandler(u'Delete')
  def handleDelete(self, action):
    # Delete the item from the address book
    item = self.getContent()
    addressbook = item.__parent__
    del addressbook[item.__name__]
    # Reset the selected item
    ISession(self.request)[SESSION_KEY]['selectedItem'] = None
  @button.buttonAndHandler(u'Done')
  def handleDone(self, action):
    # Reset the selected item
    ISession(self.request)[SESSION_KEY]['selectedItem'] = None
-------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: browser.py
Type: text/x-python
Size: 5674 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20080228/3d951044/browser.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: classes.py
Type: text/x-python
Size: 591 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20080228/3d951044/classes.py
-------------- next part --------------
<configure
	xmlns="http://namespaces.zope.org/zope"
	xmlns:browser="http://namespaces.zope.org/browser"
	xmlns:z3c="http://namespaces.zope.org/z3c"
	i18n_domain="addressbook"
	>

	<z3c:template
		template="addressbook.pt"
		for=".browser.AddressBook"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		/>

	<browser:zrt-resource
		name="addressbook.css"
		file="addressbook.css"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		/>

	<browser:viewlet
		name="addressbook.css"
		view=".browser.AddressBook"
		manager="z3c.formdemo.skin.ICSS"
		class=".browser.AddressBookCSSViewlet"
		permission="zope.Public"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		weight="1000"
		/>

	<browser:zrt-resource
		name="text-shadow.js"
		file="text-shadow.js"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		/>

	<browser:viewlet
		name="text-shadow.js"
		view=".browser.AddressBook"
		manager="z3c.formdemo.skin.IJavaScript"
		class=".browser.TextShadowViewlet"
		permission="zope.Public"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		/>

	
	<class class=".classes.Car">
		<allow interface=".interfaces.ICar" />
		<require
			permission="zope.Public"
			set_schema=".interfaces.ICar" />
		</class>

	<z3c:pagelet
		name="car.html"
		for="zope.app.container.interfaces.IContainer"
		class=".browser.AddressBook"
		layer="z3c.formdemo.layer.IDemoBrowserLayer"
		permission="zope.Public"
		/>

	<adapter
		factory=".browser.AddCarLabel"
		name="title" />

	<utility
		provides="zope.app.schema.vocabulary.IVocabularyFactory"
		component=".vocabulary.carsInParent"
		name="allCars"
		/>
  
  </configure>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interfaces.py
Type: text/x-python
Size: 618 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20080228/3d951044/interfaces.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vocabulary.py
Type: text/x-python
Size: 331 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20080228/3d951044/vocabulary.py


More information about the Zope3-users mailing list