自定义 AEM 表单字段未保留

Custom AEM Form field not persisted

我尝试按照文本字段的操作方式为 AEM 表单 (AEM6.0 SP3) 创建自定义字段:/libs/fd/af/components/guidetextbox

我用相同的内容创建了 init.jsp 和 widget.jsp。 在 widget.jsp 上,然后我将一些 jQuery 添加到 autopopulate text 字段以聚焦。

<script>
var thisField = '${guideid}${'_widget'}';
    $(thisField).focusout(function() {
    $(this).val('date ' + new Date());
  });
</script>

在聚焦时,我输入文本 'ABC' 然后在聚焦时我得到文本 'date ' 但是在提交数据时,文本 'ABC' 被提交。

是否有任何 AEM API 我需要调用(而不仅仅是 jQuery .val() 函数)以便记录更改?

在 AEM Forms 中维护一个 Javascript 模型来存储值,该模型用于提交数据。现在要将值从 ui 传递到模型 XFA_EXIT_EVENT[1] 必须被触发。所以在设置值后你必须添加这行代码来持久化值

$(this).trigger(xfalib.ut.XfaUtil.prototype.XFA_EXIT_EVENT)

还有一个更好的方法是为这个特定场景创建您自己的小部件。有关详细信息,请参阅 [2]。本文适用于 AEM Form 6.1,但它也适用于 AEM 6.0。

[1] https://helpx.adobe.com/aem-forms/6/html5-forms/introduction-widgets.html

[2] https://helpx.adobe.com/aem-forms/6-1/custom-appearance-widget-adaptive-form.html

不是最好的解决方案,但我们设法通过首先调用 focus() 使其工作,例如。

$(this).focus().val('date ' + new Date());

更好的解决方案:

  1. 创建自定义函数,例如

    function initDatePicker(thisObj) { $(this).focusout(function() {thisObj.value = $(this).val();});}

  2. 更新 .content.xml 以在 initScript 中调用它,例如

将小部件添加到 canvas 时将立即包含该功能。