87228

Set a minimum limit in a custom multifield component

Question:

I have a custom multifield component with a maximum limit of 5 elements applied to the 'Add Item' button.

I need to add a similar listener logic to the 'OK' button of the dialog box to check if the minimum number of items (3) have been added or not.

How can that be achieved ? I didn't find any sample code to add a listener code to the button ..

Answer1:

I've done this same sort of thing with a listener on the beforesubmit event of the Dialog (see beforesubmit for CQ.Dialog at <a href="http://dev.day.com/docs/en/cq/current/widgets-api/index.html" rel="nofollow">http://dev.day.com/docs/en/cq/current/widgets-api/index.html</a> - search for "Dialog"):

<listeners jcr:primaryType="nt:unstructured" beforesubmit="function(dialog){return myNamespace.myCustomFunction(dialog);}"/>

Then the custom JavaScript function, included on the page via a client library, could be something like this:

myNamespace = {}; myNamespace.myCustomFunction = function (dialog) { var isValid = function () { var valStatus = true; ... custom JavaScript/jQuery to check if 3 items exist ... return valStatus; }; if (!isValid()) { CQ.Ext.Msg.show({title: 'Validation Error', msg: 'Must contain at least 3 items!', buttons: CQ.Ext.MessageBox.OK, icon: CQ.Ext.MessageBox.ERROR}); return false; } else { return true; } }

Recommend

  • JSON - Not working in Internet Explorer 8
  • How to cancel submit on AjaxForm
  • bootstrap 3 modal in meteor not showing
  • How do I get rid of the Eclipse Find/Replace Bar
  • Create child Window of another process's HWND? (e.g. screensaver preview)
  • Access 2007 forms with parameterized RecordSource
  • Powerpoint VBA Macro Save As Dialog File Filter
  • Bootstrap modal closes when dropdownlist inside fires selected index changed event
  • Returning this from a constructor function in JS
  • dismiss Progress Dialog in another Activity … Android
  • How to remove all of a jQuery UI dialog when it is closed
  • Making Google Visualization - Annotation Chart to work in GWT
  • Can't remove headers after they are sent
  • Android application: how to use the camera and grab the image bytes?
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • How can I sort a a table with VBA with given text condition?
  • d3 v4 drag and drop with TypeScript
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • JQuery Internet Explorer and ajaxstop
  • Is it possible to access block's scope in method?
  • How to clear text inside text field when radio button is select
  • Alert pop up with LWUIT
  • Scrapy recursive link crawler
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • Cassandra Data Model
  • php design question - will a Helper help here?
  • Acquiring multiple attributes from .xml file in c#
  • Why joiner is not used after Sequence generator or Update statergy
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Getting Messege Twice Using IMvxMessenger
  • Linking SubReports Without LinkChild/LinkMaster
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • Does armcc optimizes non-volatile variables with -O0?
  • How can i traverse a binary tree from right to left in java?
  • Python/Django TangoWithDjango Models and Databases
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?