如何在CQ5中限制多字段中的元素数量? [英] How to limit the number of elements in multifield in CQ5?

查看:93
本文介绍了如何在CQ5中限制多字段中的元素数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第CQ5天开发该网站,但遇到了问题. 我正在创建一个组件,并为其进行对话.我在对话框中使用了组成元素"multifield",其中包含多个元素"pathfield".如何设置特定数量的元素"pathfield"并删除按钮"+"和-"?

I develop the site with Day CQ5 and was faced witha problem. I'm creating a component, and the dialogue for it. I use in the dialog for the component element "multifield", which contains several elements "pathfield." How can I set a specific number of elements "pathfield" and remove buttons "+" and "-"?

推荐答案

本周我遇到了这个确切的问题:)

I've come across this exact problem this week :)

似乎默认情况下您不能限制编辑器可以输入的项目数.为解决此问题,我在

It seems that by default you can't limit the number of items the editor can enter. To resolve the issue, I created an overlay of the Multifield.js placed at

/apps/cq/ui/widgets/source/widgets/form/MultiField.js

我在多字段下的fieldConfig节点上添加了对'limit'属性设置的检查.如果存在&不为零,它将以此为用户可以添加的最大字段数.

I've added a check for a 'limit' property set on the fieldConfig node under the multifield. If present & not zero, it will use this as the max number of fields a user can add.

不想通过发布完整的叠加图来解决版权问题,但是我在以下方面进行了更改:

Don't want to get into copyright issues by posting the full overlay, but the changes I made where as follows:

在构造函数(第53行)中,添加检查以从fieldConfig节点获取limit的值:

In the constructor (line #53), add in a check to get the value of limit from the fieldConfig node:

if (!config.fieldConfig.limit) {
        config.fieldConfig.limit = "0";
}

在"+"按钮(第71行)的处理程序中,将功能更改为以下内容:

In the handler for the "+" button (line #71) change the function to the following:

if(config.fieldConfig.limit == 0 || list.items.getCount() <= config.fieldConfig.limit) {
    list.addItem();
} else {
    CQ.Ext.Msg.show({
        title: 'Limit reached',
        msg: 'You are only allowed to add ' + config.fieldConfig.limit + 
             ' items to this module',
        icon:CQ.Ext.MessageBox.WARNING,
        buttons: CQ.Ext.Msg.OK
    });
}

我没有删除按钮,而是创建了一个弹出窗口来通知编辑器"N是允许的最大字段数".

Rather than removing the buttons, I've just created a pop-up to inform the editor that 'N is the max number of fields allowed'.

简单的更改,但能完成工作!希望这是有用的.

Simple change, but does the job! Hope this is of use.

这篇关于如何在CQ5中限制多字段中的元素数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆