Expand my Community achievements bar.

How to make 'limit' property set on the fieldConfig node under the multifield configurable.

Avatar

Level 9

Hi All,

I am following the article http://letsaem.blogspot.in/2015/12/add-limit-to-number-of-elements-in.html to make this work.

However, in addition  'limit' property value has to be configurable[i.e, it has to pick value from an authorable textfield in component dialog].

Any thoughts/snippet on this will be helpful.

3 Replies

Avatar

Administrator

Hi 

Please have a look at this community article:- 

Link:-http://letsaem.blogspot.in/2015/12/add-limit-to-number-of-elements-in.html

//

Step 1:
Let's create a basic multifield xtype node by creating a node of type and node name as list with following properties
 
  • name (string)./list
  • xtype (string)multifield
Step 2:
create a fieldConfig node under the node created in step 1 with node name fieldConfig and type nt:unstructured with the following properties
 
  • xtype (string)textfield
  • limit (long)3 
Above property will be used to configure the max number of items

Step 3:
create a listener node under the node created in step 1 with node name listeners and type nt:unstructured with the following properties
 
  • removeditem (string): 
         function(list) {
      var length = list.items.length;
        if (length <= list.fieldConfig.limit) {
          list.items.items[length - 1].show();
        }
    }
  • beforeadd (string): 
 
    function(list, component, index) {
      var length = list.items.length;
      var addButton = list.items.items[length - 1];
      if (length == list.fieldConfig.limit) {
        addButton.hide();
      }
    }


After completing the above steps the nodes will look like this.
final node

 

 

 

Reference Link 2:- http://myadobecq.blogspot.in/2013/12/how-to-limit-number-of-fileds-in.html

Link 3:- http://stackoverflow.com/questions/10018858/how-to-limit-the-number-of-elements-in-multifield-in-cq5

I hope this will help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 9

Hi Kautuk,

Yes, I have used the same article and it is working. However, I want to make the limit field configurable[i.e, I should be able to populate limit field value from another field[say a textfield/dropdown] in the component dialog]

Avatar

Level 9

Hi All,

Suppose I enter 3 in a textfield [property xyz], adding a listener there to get the value. Able to get the value. But not sure how to populate that to limit field in fieldconfig[in the above mentioned article]

Trying the below:

function(comp) { var dlg = comp.findParentByType('dialog'); var sel = dlg.getField('./xyz').getValue();console.log(sel); var field = dlg.getField('limit');field.setValue(sel);}

Any thoughts/snippet will be helpful.