An Archetypes widget that controls the vocabulary or display of otheer fields on an edit page
Project description
Overview
This is an Archetypes widget which controls the vocabulary or display of other fields on an edit page. It needs to be given information about which fields to control and how to control them.
To install it just extract into your products directory, restart zope, and install it with the QuickInstaller.
Usage
To use it just create a field like:
StringField( name='master_field', default='', vocabulary=DisplayList( (('week', 'Week'), ('wedding','Wedding'), ('winona','Winona'), ('winter', 'Winter'), ('weather','Weather'), ('cow', 'Cow'), ), ), widget=MasterSelectWidget( label='Test Widget', description='Test this', slave_fields=( {'name': 'slave_field_name', 'action': 'vocabulary', 'vocab_method': 'mySlaveVocabularyMethod', 'control_param': 'my_method_parameter', }, ), ), ),
You can use any field type compatible with a normal SelectWidget. And you may use any of the normal SelectWidget parameters (except ‘format’, which must be set to ‘select’). It will appear and behave like a normal SelectWidget, but changes in this widget will affect the widgets described in the slave_fields parameter.
Parameters
All the magic happens in the slave_fields parameter which should be a sequence of mappings. Each mapping is a description of a field controlled by this master field:
- name
The name of the field to control on when the selection changes. The controlled field/widget may be of any type unless the ‘vocabulary’ or ‘value’ action is used. When the action is ‘vocabulary’, the field must use either a MultiSelectionWidget, a SelectionWidget, or a MasterSelectWidget any of which must have the ‘format’ parameter set to ‘select’ (this is the default only for MasterSelectWidget). For ‘value’, the widget must be simple enough to change the current value using element.value or elem.selectedIndex (StringWidget, SelectionWidget, AutoCompleteWidget, maybe others).
- action
The type of action to perform on the slave field. This can be ‘vocabulary’, which alters the vocabulary of the slave field using an XMLHttpRequest call; ‘hide’ or ‘show’ which sets the slave field’s visibility style attribute; ‘enable’ or ‘disable’ which marks the target widget as enabled or disabled; or ‘value’ which alters the value of another simple widget (StringWidget) on selection change using an XMLHttpRequest call. To use the ‘vocabulary’ action, the slave field must meet the widget requirements stated above. To use the ‘enable’/’disable’ actions, the field must use a HTML widget that can be enabled/disabled.
- vocab_method
The name of a method to call to retrieve the dynamic vocabulary for the slave field, or the value for the slave field when ‘value’ is used. For ‘vocabulary’, this must return a DisplayList. For ‘value, it must return a string or msg_id. The method must accept a parameter which will be used to pass the new value selected in the master widget. The name of this parameter defaults to ‘master_value’, but any name may be used as long as it is specified using the control_param element. Used only with ‘action’:’vocabulary’ or ‘action’:’value’. When used with archetypes.schemaextender, the vocabulary method can be defined on schema extension class.
- control_param
As described above, this is the name of the paramter used when calling the vocab_method. Used only with ‘action’:’vocabulary’ or ‘action’:’value’.
- hide_values
A sequence of values which when selected in the master widget cause the slave field/widget to be hidden, shown or disabled. The method used is determined by the ‘action’ element. Used only with ‘action’:’hide’, ‘action’:’enable’, ‘action’:’disable’ or ‘action’:’show’.
A single MasterSelectWidget may control any number of slave fields, new fields are controlled by adding new mappings to the slave_fields list/tuple. A field which is the target of a MasterSelectWidget action may itself use a MasterSelectWidget to control other fields.
The MasterSelectDemo type includes a number of master and slave widgets in different configurations.
To enable the demo type go to portal_setup, hit the Import tab, select the MasterSelectWidget demo profile and click the Import all steps button at the bottom.
Enjoy!
Credits
- Author
Alec Mitchell: apm13@columbia.edu
- Contributor
Dorneles Tremea: deo@plonesolutions.com
Changelog
0.4.6 (2014-06-10)
Use a ‘fast’ jQuery transition to show/hide slave fields.
Do not check undefined checkboxes at initialisation (jQuery > 1.6 required) (fixes https://github.com/plone/Products.MasterSelectWidget/issues/1) [fRiSi]
0.4.5 (2011-10-10)
Try to use embedded json (Python 2.6+). [thomasdesvenain]
Avoid warnings at startup. [thomasdesvenain]
Fixed ajax vocabulary values translation. [thomasdesvenain]
Vocabulary ajax methods can be defined on archetypes.schemaextender extension class. [thomasdesvenain]
0.4.4 - 2010-04-16
fixed master boolean widget issues in Plone 4.0 due to jQuery changes. (fixes http://plone.org/products/masterselectwidget/issues/1) [alecm]
fixed demo content (could not be added since 0.4.3 due to different productnames in registerType and the FTI) [fRiSi]
0.4.3 - 2010-03-15
Correct missing return from selected values in the slave field [danipessanha]
compatibility with most recent archetypes versions (the package parameter of registerType is no longer optional, see http://dev.plone.org/archetypes/changeset/11184#file4) [fRiSi]
0.4.2 - 2009-04-01
Correct missing return value from .browser.MasterSelectJSONValue.getVocabulary [alecm]
0.4.1 - 2009-03-24
Re-release, bad egg upload. [elro]
0.4 - 2009-03-24
Allow views to be sub-classed more easily. [elro]
0.3 - 2009-03-19
Converted to an egg [mj]
Moved configuration (skin, demo type) to GenericSetup profiles. [mj]
Added a MasterBooleanWidget to the demo. [mj]
Refactored javascript to use jQuery and a view for the AJAX results. [mj]
Added simple support for updating kupu slave fields. [ender]
Added MasterBooleanWidget [gawel]
Replace old dtml with browser view [gawel]
Updated docs, did some general small cleanup and added examples for the new ‘show’/’enable’ actions. [deo]
Added new ‘enable’ action, which only activate the slave field(s) when a particular value is selected in the master field. [deo]
Added new ‘show’ action, which only display the slave field(s) when a particular value is selected in the master field. [deo]
Made sure to keep the values initialy selected when using a dynamic vocabulary. [deo]
0.2.2 - 2005-11-09
Fixed some IE bugs and made hiding use display=”none” to remove the element from the page. Thanks to Yuta Kashino for pinting these out. [alecm]
Added new action for changing value in StringFields using simple widgets. Thanks to Joachim Koenig-Baltes for the idea and patch. [alecm]
0.2.1 - 2005-06-17
Fixed bug that caused unnecessary js alert when hiding some widget types. [alecm]
0.2 - 2005-06-16
Added support for hiding and disabling compound widgets like Boolean and InAndOut. [alecm]
Added the ability for a single master to apply multiple actions on a single slave. Now a master widget can both hide and change the vocabulary of a slave field. Just add an entry to slave_fields for each action desired. [alecm]
Made getXMLSelectVocab accept methods that return lists or tuples instead of only DisplayLists. DisplayLists are preferred though. [alecm]
0.1 - 2005-06-15
Initial checkin, ready for testing. [alecm]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for Products.MasterSelectWidget-0.4.6.zip
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3f7d61ff96a4505ea25f5d915533ad9b1166b28a1faf6a529cb0981b9781503 |
|
MD5 | e0b34091acc949395bc34fd18958b52e |
|
BLAKE2b-256 | fde7d7f68b7d6e4aecb00d1d8000b4da233aa2260752214d13eb4094b527a4b7 |