2015-11-11 39 views
0

我正在尝试使用guidetextbox(文本框)作为基础来创建自定义表单字段。把我的定制逻辑之前,我创建了一个文件夹的分量和内我把.content.xml如下:创建具有必填字段的自定义aem表单字段

<?xml version="1.0" encoding="UTF-8"?> 
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" 
allowedParents="[*/parsys, */*layout]" 
componentGroup="Adaptive Form" 
jcr:description="AEM Form Custom input field" 
jcr:primaryType="cq:Component" 
jcr:title="AEM Form Custom input field" 
sling:resourceSuperType="/libs/fd/af/components/guidetextbox"> 

<cq:template 
    jcr:primaryType="nt:unstructured" 
    jcr:title="Custom input" 
    guideNodeClass="guideCustomInput" /> 
</jcr:root> 

我试图通过设置字段作为强制性的(从dialog.xml)来测试这一点,但字段保持可选状态,在文本字段周围没有红色边框。

有人可以建议还需要什么吗?

回答

0

据我所知,你必须在你使用它的组件的dialog.xml中将该字段设置为强制。 通常这是通过添加

allowBlank="false" 

到dialog.xml做

1

如果您使用的触摸用户界面的对话框,您如果使用的是旧Ext JS的对话应该增加

required="{Boolean}true" 

,则应添加

allowBlank="false" 

作为对话项目的属性。

0

您不应该更改guideNodeClass属性,因为这是AEM表单域的内部工作。它应该保持为guideTextBox。

另外作为resourceSuperType不应该是绝对路径的最佳实践。最终代码如下所示

<?xml version="1.0" encoding="UTF-8"?> 
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" 
allowedParents="[*/parsys, */*layout]" 
componentGroup="Adaptive Form" 
jcr:description="AEM Form Custom input field" 
jcr:primaryType="cq:Component" 
jcr:title="AEM Form Custom input field" 
sling:resourceSuperType="fd/af/components/guidetextbox"> 

<cq:template 
    jcr:primaryType="nt:unstructured" 
    jcr:title="Custom input" 
    guideNodeClass="guideTextBox" /> 
</jcr:root> 
0

对于AEM表单,您需要设置mandatory =“true”,不是必需的或allowBlank。您可以直接在xml的字段中执行此操作,也可以通过强制复选框通过Forms UI执行此操作。