Multifield beforeadd listener | Community
Skip to main content
Level 3
October 16, 2015
Solved

Multifield beforeadd listener

  • October 16, 2015
  • 1 reply
  • 1229 views

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; } } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mayank_Saklecha
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; } } }

1 reply

Mayank_SaklechaAccepted solution
Level 3
October 16, 2015
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; } } }