简体   繁体   English

Plone5 Mockup Widgets就像pat-pickadate不适用于动态生成的内容

[英]Plone5 Mockup Widgets like pat-pickadate not working for dynamically generated content

Assume the following silly code fragment in a plone 5 page template: 在plone 5页面模板中假设以下愚蠢的代码片段:

<input id="foo" class="pat-pickadate" />

<input id="bar" />

<script type="text/javascript" >
       $('#bar').click( function () {
            $('#bar').addClass("pat-pickadate");
       });
</script>

You will get two inputs. 你会得到两个输入。 The first is a nice calendar input and the second is empty at start. 第一个是很好的日历输入,第二个是开始时为空。 After clicking the second input its class will be set to "pat-pickadate" - like the first - but no calendar is rendered. 单击第二个输入后,其类将设置为“pat-pickadate” - 与第一个类似 - 但不会呈现日历。

I came across this while trying to find the reason, why my jquery-UI overlays displaying plone add, and edit views do no longer (Plone5) show calendar widgets at all. 我试图找到原因时遇到了这个问题,为什么我的jquery-UI叠加显示plone添加,编辑视图不再(Plone5)显示日历小部件。

Is this behavior intended? 这种行为是有意的吗? If so, what is the correct way to use mockup widgets in forms dynamically obtained by AJAX calls in Plone 5? 如果是这样,在Plone 5中通过AJAX调用动态获取的表单中使用模型小部件的正确方法是什么? Is there some magic call to inform the Mockup machinery of the DOM change? 是否有一些神奇的召唤通知Mockup机制DOM的变化?

I read that Mockup has its own overlay technique, but it is hard to rewrite some 600 lines of complex JS code just to get a simple widget right. 我读到Mockup有自己的叠加技术,但很难重写大约600行复杂的JS代码,只是为了得到一个简单的小部件。

I was not able to find any documentation nor examples on this topic. 我无法找到关于此主题的任何文档或示例。 Can anyone put me in the right direction, please? 有人能把我放在正确的方向吗?

Patterns are initialized at load time, if your DOM changes and contains new elements supposed to be rendered using a pattern, you need to call Registry.scan . 模式在加载时初始化,如果DOM更改并包含应该使用模式呈现的新元素,则需要调用Registry.scan

To do it, you will need to change your script like this: 要做到这一点,您需要像这样更改脚本:

require([
    'jquery',
    'pat-registry'
], function($, Registry) {
    $('#bar').click( function () {
        $('#bar').addClass("pat-pickadate");
        Registry.scan($('#bar'));
    });
})

The script mustn't be inline, because nothing guarantees that JQuery and/or require are already loaded. 该脚本不能内联,因为没有任何保证已经加载了JQuery和/或require。 So put your code in a separated JS file, and make sure it is loaded in your page using one of those 2 ways: 因此,将您的代码放在一个单独的JS文件中,并确保使用以下两种方法之一将其加载到您的页面中:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM