Expand my Community achievements bar.

SOLVED

Multifield beforeadd listener

Avatar

Level 4

I'm adding a beforeadd listener to a multifield to limit the number of items that can be added. I see the message when I try and add more than the limit, no more items get added, but as the xtype configured to the the multifield item is required (cannot be empty) it doesn't let me click 'OK' on the dialog anymore, telling me I need to complete all fields.

function(list,component,index) { if(this.fieldConfig.limit!=0) { if((list.items.getCount()-1) > this.fieldConfig.limit) { CQ.Ext.Msg.show( { title : 'Limit reached', msg : 'You are only allowed to add ' + this.fieldConfig.limit + ' links', buttons : CQ.Ext.Msg.OK, fn : function(buttons) { if(buttons == "ok") return false; }, icon : CQ.Ext.MessageBox.WARNING }); return false; } } }
1 Accepted Solution

Avatar

Correct answer by
Level 3
Try Below Code, it should work:
function(list,component,index) { if(this.fieldConfig.limit!=0) { if((list.items.getCount()-1) > this.fieldConfig.limit) { CQ.Ext.Msg.show( { title : 'Limit reached', msg : 'You are only allowed to add ' + this.fieldConfig.limit + ' links', buttons : CQ.Ext.Msg.OK, icon : CQ.Ext.MessageBox.WARNING }); return false; } } }

View solution in original post

1 Reply

Avatar

Correct answer by
Level 3
Try Below Code, it should work:
function(list,component,index) { if(this.fieldConfig.limit!=0) { if((list.items.getCount()-1) > this.fieldConfig.limit) { CQ.Ext.Msg.show( { title : 'Limit reached', msg : 'You are only allowed to add ' + this.fieldConfig.limit + ' links', buttons : CQ.Ext.Msg.OK, icon : CQ.Ext.MessageBox.WARNING }); return false; } } }