This week I ran into this problem :)
It seems that by default you cannot limit the number of elements that the editor can enter. To solve the problem, I created a Multifield.js overlay placed in
/apps/cq/ui/widgets/source/widgets/form/MultiField.js
I added a check for the "limit" property set in the Config node field under multifield. If present, and not zero, he will use this as the maximum number of fields that the user can add.
Don't want to deal with copyright issues by posting a full overlay, but the changes I made are as follows:
In the constructor (line # 53) add a check to get the limit value from the Config node field:
if (!config.fieldConfig.limit) { config.fieldConfig.limit = "0"; }
In the "+" button handler (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 }); }
Instead of deleting the buttons, I just created a pop-up window to tell the editor that "N is the maximum number of fields allowed."
Simple change, but does the job! Hope this is helpful.
anotherdave
source share