OptionalFields
OptionalFields
Hide and show an object's fields regarding a context
Section(s): back office, data model, ergonomics, plugin, standard plugin, templates
Parameters
- pathToOptionalBundle
- Path from SAN directory to optional bundle file used for configuring global and layout specialized option fields default visibility and typing properties names
- pathToPrototypeJS
- Path to prototype.js. Used by BO only, should not be set unless you're sure you don't have prototype linked by default.
Description
Provides functionalities for hiding / showing properties regarding a context. The context is by priority :
- The application
- The layout of the site (in a multisite platform)
- A typing property value.
When defining object properties in structure mode, properties for which the first character of the caption (label) field attribute is an underscore ( _ ) will be hidden by default in view and edit modes (dataview and dataedit form actions) if and only if these fields are not mandatory.
Therefor it is recommended to set those fields as not listed.
In order to be shown, one of the three following conditions must be true :
- The fields bundle config file contains a key [form_object].[fieldname] with true as value and [layout].[form_object].[fieldname] is not false
- The fields bundle config file contains a key [layout].[form_object].[fieldname] with true as value
- The typing field has its option set to display the field.
[form_object] represents the name of the object type being viewed/edited
[fieldname] is the name of the field to be shown
[layout] is the name of the site layout (in a multisite context)
The default typing field is the one named type. It must be a child. It can be named differently for a specific object by defining in the bundle config the key : config_typingfield_[form_object].
When the child value is changed, fields are shown/hidden thanks to the config property of the typing child.
The config property consists in a list of coma (or whitespace) separated list of fields name to show when the child is selected.
Exemples
Lets assume we have :1. An object named objectatype defined this way :

With datas :
| name | config |
| type1 | foobar |
| type2 | foobar foo |
| type3 | foo |
2. An object named objecta defined this way :

3. A bundle config defines as :
objecta.foo=true layout1.objecta.foo=false layout1.objecta.bar=true
In a site with a layout other than layout1,
foo will always be visible
bar will never be visible
foobar will be visible if type property is type1 or type2
In a site with a layout equals to layout2,
foo will only be visible when type property is type1 or type2
bar will always be visible
foobar will be visible if type property is type1 or type2
Tips
When you want to type an object (ex: aaa), try to name the typing object aaatype or typeaaa : This way when editing an instance of aaatype (or typeaaa), aaa fields will be loaded, and the configuration will be easier :

