Message Boards

Add limitation on Liferay AutoFields section

niroshansg96123321 Premarathne, modified 8 Years ago.

Add limitation on Liferay AutoFields section

New Member Posts: 5 Join Date: 4/8/16 Recent Posts
Hi,

I am new to Liferay and AUI and I was able to successfully integrate auto field plugin in to my existing application using following source.

<div id="phone-fields">
<div class="lfr-form-row lfr-form-row-inline">
<div class="row-fields">
<aui:column first="true">
<aui:input name="Number1" required="true" label="Number"></aui:input>
</aui:column>
<aui:column>
<aui:select name="size1" label="Size">
<aui:option value="-1">---Select Container---</aui:option>
<aui:option value="20">20"</aui:option>
<aui:option value="40">40"</aui:option>
<aui:option value="45">45"</aui:option>
</aui:select>
</aui:column> </div>
</div>
</div>

And related script was

<aui:script use="liferay-auto-fields">
var autoFields = new Liferay.AutoFields(
{
contentBox: '#phone-fields',
fieldIndexes: '<portlet:namespace />phonesIndexes'
}
);
autoFields.render();
</aui:script>

But I need to restrict number of fields can be added based on user defined value. Can some one please explain whether it's possible to do using autofield.? I try to find similar sort of problem but I could not able to find one.
thumbnail
Yogesh Sharma, modified 8 Years ago.

RE: Add limitation on Liferay AutoFields section

Junior Member Posts: 32 Join Date: 3/7/12 Recent Posts
Hi Niroshan,

Each time user clicks on add icon, "clone" event is fired. You can apply your logic in it to hide add button. Similarly "delete" event is fired in case of deletion.

Selector with
AUI().all('<auto field form container class> .lfr-form-row:visible').size()</auto>
might be used to find currently visible fields.

Hope it will would be helpful for you.

-- Yogesh
niroshan Premarathne, modified 8 Years ago.

RE: Add limitation on Liferay AutoFields section

New Member Posts: 5 Join Date: 4/8/16 Recent Posts
Hi Yogesh,

Thanks to point out it. I'll check according to your comment.

-
Nirmal
Manish Luste, modified 4 Years ago.

RE: Add limitation on Liferay AutoFields section

New Member Posts: 3 Join Date: 5/25/17 Recent Posts
Hi Yogesh,
       every time getting size "0" during add/delete field. am i mistaking something in below syntax?
<aui:script use="liferay-auto-fields">
 new Liferay.AutoFields({
     contentBox: '#document-auto-fields-container',
     fieldIndexes: '<portlet:namespace />fieldIndexes',
      on: {
               'clone': function(event) {
                   alert("-- Add --");
                   console.log(AUI().all('document-auto-fields-container.lfr-form-row:visible').size());
                   
               },
               'delete': function(event) {
                   alert("-- Delete --");
                   console.log(AUI().all('document-auto-fields-container.lfr-form-row:visible').size());
               }
      }
     
 }).render();
</aui:script>


Thanks & Regards
thumbnail
Yogesh Sharma, modified 4 Years ago.

RE: Add limitation on Liferay AutoFields section

Junior Member Posts: 32 Join Date: 3/7/12 Recent Posts
Hi Manish, In your selector statement, you are not using . (dot) before class name, could this be reason?Can you please check if following code works:
console.log(AUI().all('.document-auto-fields-container .lfr-form-row:visible').size());

This thread is quiet old however, can you please share which Liferay version you are trying your code on?

--
​​​​​​​Yogesh