我正在创建一个包含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>
Run Code Online (Sandbox Code Playgroud)
我能够编辑内容,并保存内容.但是我有两个问题 - 1)当对话框加载时,它总是空的,当我重新打开对话框时它不显示保存的内容2)向上和向下箭头不再工作.任何解决这些问题的建议都非常感谢.非常感谢你.
多字段xtype的字段配置只占用一个项目(即,您可以在其中包含一个文本字段.当配置多个值时,它们将被存储为称为链接的多值属性,当只配置一个值时,它将被存储为单个值属性称为链接).多字段中配置的整个数据将作为链接属性存储在节点中.你将无法将它们作为"jcr:title"和"jcr:url".
您应该创建一个自定义的xtype说"linksXtype"存储的"JCR:标题"和"JCR:URL",通过一些模式分离一个字符串说"***"("JCR:标题***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);
Run Code Online (Sandbox Code Playgroud)
将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>
Run Code Online (Sandbox Code Playgroud)
要获取值,请迭代存储为links属性的字符串数组,并将每个字符串拆分为"***"
编辑:
ACS-Commons软件包下的Adobe咨询服务提供了一个更优雅的多字段窗口小部件来处理这个用例.它简化了方法,并且无需为每个必需字段组合编写自定义xtype.数据以JSON格式存储,并附带taglib以从节点中提取数据.链接:http://adobe-consulting-services.github.io/acs-aem-commons/features/widgets.html#multi-field-panel-since-150