Thursday, 12 November 2015

Multifields with different xtypes

Multifield widgets are used to allow authors to enter a dynamic number of data points. By default, these data points are entered as simple textfield controls. How can that be changed to allow for other types of input?
Here is an example of a multifield whose inner widget’s xtype is pathfield:
Problem: To create a multifield, a new widget of xtype multifield me be created. But xtype is traditionally what defines the input type, so we can’t change that directly.
Solution: Create another widget inside the multifield called fieldConfig and use that to customize the widget.
The node images is the multifield xtype.  It’s where the name, in this case ./images, is specified.  Within that widget node, create another widget node named fieldConfig.  Specify additional properties, like xtype: pathfield within that node.
Extracting the properties: retrieving data stored in this field is done in the same manner as standard multifield components.
<%@include file="/libs/foundation/global.jsp"%>
Multifield Test Component<br/>
// String[] images = properties.get("images", String[].class); // default is null
String[] images = properties.get("images", new String[0]); // default is empty array
for (int i = 0; i < images.length; i++) {
<img src="<%= images[i] %>"></img><br/>

No comments :

Post a comment