我正在创建一个有2个文本字段的多字段组件。下面是我的对话框xml。
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
title="dialog"
xtype="dialog">
<items jcr:primaryType="cq:WidgetCollection">
<links
jcr:primaryType="cq:Widget"
fieldLabel="QuickLinks"
name="./links"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="multifield">
<items jcr:primaryType="cq:WidgetCollection">
<title
jcr:primaryType="cq:Widget"
fieldLabel="Title"
hideLabel="{Boolean}false"
name="./jcr:title"
xtype="textfield"/>
<url
jcr:primaryType="cq:Widget"
fieldLabel="URL"
name="./jcr:url"
xtype="textfield"/>
</items>
</fieldConfig>
</links>
</items>
</jcr:root>我可以编辑内容,然后保存内容。然而,我有两个问题- 1)当对话框加载时,它总是空的,当我重新打开对话框时,它不显示保存的内容2)向上和向下箭头不再起作用。任何解决这些问题的建议都是非常感谢的。非常感谢。
发布于 2014-10-10 15:33:41
multifield xtype的字段配置只接受一项(即你可以在其中有一个文本字段)。当配置了多个值时,它们将被存储为称为链接的多值属性,而当只配置了一个值时,将被存储为称为链接的单值属性。在多字段中配置的整个数据将作为links属性存储在节点中。您将无法将它们作为"jcr:title“和"jcr:url”获取。
您应该创建一个自定义xtype,名为"linksXtype“,它将"jcr:title”和"jcr:url“存储为由模式”*“分隔的单个字符串(”jcr:title*jcr:url“)。
您可以在此处找到创建自定义xtype的详细信息:link
xtype可以像这样创建:
Ejst.CustomWidget = CQ.Ext.extend(CQ.form.CompositeField, {
/**
* @private
* @type CQ.Ext.form.TextField
*/
hiddenField: null,
/**
* @private
* @type CQ.Ext.form.ComboBox
*/
jcrtitle: null,
/**
* @private
* @type CQ.Ext.form.TextField
*/
jcrurl: null,
constructor: function(config) {
config = config || { };
var defaults = {
"border": false,
"layout": "table",
"columns":2
};
config = CQ.Util.applyDefaults(config, defaults);
Ejst.CustomWidget.superclass.constructor.call(this, config);
},
// overriding CQ.Ext.Component#initComponent
initComponent: function() {
Ejst.CustomWidget.superclass.initComponent.call(this);
this.hiddenField = new CQ.Ext.form.Hidden({
name: this.name
});
this.add(this.hiddenField);
this.jcrtitle = new CQ.Ext.form.TextField({
fieldLabel:"Jcr url",
cls:"ejst-customwidget-1",
listeners: {
change: {
scope:this,
fn:this.updateHidden
}
},
optionsProvider: this.optionsProvider
});
this.add(this.jcrtitle);
this.jcrurl = new CQ.Ext.form.TextField({
fieldLabel:"Jcr Title",
cls:"ejst-customwidget-2",
listeners: {
change: {
scope:this,
fn:this.updateHidden
}
}
});
this.add(this.jcrurl);
},
// overriding CQ.form.CompositeField#setValue
setValue: function(value) {
var parts = value.split("/");
this.jcrtitle.setValue(parts[0]);
this.jcrurl.setValue(parts[1]);
this.hiddenField.setValue(value);
},
// overriding CQ.form.CompositeField#getValue
getValue: function() {
return this.getRawValue();
},
// overriding CQ.form.CompositeField#getRawValue
getRawValue: function() {
return this.jcrtitle.getValue() + "***" +
this.jcrurl.getValue();
},
// private
updateHidden: function() {
this.hiddenField.setValue(this.getValue());
}
});
// register xtype
CQ.Ext.reg('linksXtype', Ejst.CustomWidget);将dialog.xml更改为如下所示
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
title="dialog"
xtype="dialog">
<items jcr:primaryType="cq:WidgetCollection">
<links
jcr:primaryType="cq:Widget"
fieldLabel="QuickLinks"
name="./links"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="linksXtype">
</fieldConfig>
</links>
</items>
</jcr:root>要获取这些值,请迭代存储为links属性的字符串数组,并将每个字符串拆分为“*”
编辑:
其ACS-Commons包下的Adobe consultancy提供了一个更优雅的multifieldpanel小部件来处理此用例。它简化了方法并消除了为每个必填字段组合编写自定义xtype的需要。数据以JSON格式存储,并附带标记库,用于从节点提取数据。链接:http://adobe-consulting-services.github.io/acs-aem-commons/features/widgets.html#multi-field-panel-since-150
https://stackoverflow.com/questions/26290908
复制相似问题