Fórumok

AutoField example

thumbnail
Lennart Job, módosítva 13 év-val korábban

AutoField example

New Member Bejegyzések: 3 Csatlakozás dátuma: 2011.04.01. Legújabb bejegyzések
Hi everyone!

Could anyone please give me an example of how to use AutoFields to duplicate fields in forms? I think I'm having trouble with the selectors for the correct field. I've already checked the source code in .../portal-web/docroot/html/js/liferay/auto_field.js but I didn't find my mistake.
Right now, it correctly displays three input fields for my test lists' three members. However there are no +/- buttons to add another input.

Thanks!

Lennart

Here's my code:
<aui:fieldset>
	&lt;%
		int index = 0;
		for (String name : teamMemberNames) {
			index++;
	%&gt;
	<div class="lfr-form-row lfr-form-row-inline">
		<div class="row-fields">
			<aui:input name="<%= &quot;teamMember&quot; + index %>" label="<%= &quot;Projektmitglied &quot; + index%>" value="<%=name %>" onFocus="this.select()" inlineLabel="left" size="40" />
		</div>
	</div>
	&lt;%
		}
	%&gt;
</aui:fieldset>

<aui:script use="liferay-auto-fields">
	new Liferay.AutoFields(
		{
			container: '#additionalMembers &gt; fieldset', 
			baseRows: '#additionalMembers &gt; fieldset .lfr-form-row'
		}
	).render();
</aui:script>
thumbnail
Lennart Job, módosítva 13 év-val korábban

RE: AutoField example

New Member Bejegyzések: 3 Csatlakozás dátuma: 2011.04.01. Legújabb bejegyzések
I've solved it myself. As there is a lack of documentation on this feature I'll post my solution here.
Even though the documentation of AutoFields says that container and baseRows are mandatory parameters, they obviously aren't. If you don't use these parameters, the functions provides them for you. You just have to provide the contentBox to duplicate.
If you want to read the duplicated fields' contents you have to provide an array of indexes.
I've used \liferay-portal-src-6.0.6\portal-web\docroot\html\portlet\enterprise_admin\common\additional_email_addresses.jsp and the corresponding Java classes as a role model.

Here's my code:
<aui:fieldset id="member-fields">
	&lt;%
		for (int i = 0; i &lt; teamMemberIndexes.length; i++) {
					int teamMemberIndex = teamMemberIndexes[i];
					String name = teamMemberNames.get(i);
	%&gt;
	<div class="lfr-form-row lfr-form-row-inline">
		<div class="row-fields">
			<aui:input name="memberName" fieldParam="<%= &quot;memberName&quot; + teamMemberIndex %>" label="Projektmitglied" value="<%=name %>" onFocus="this.select()" inlineLabel="left" size="40" />
		</div>
	</div>
	&lt;%
		}
	%&gt;
</aui:fieldset>
<aui:script use="liferay-auto-fields">
	new Liferay.AutoFields(
		{
			contentBox: '#member-fields',
			fieldIndexes: '<portlet:namespace />teamMemberIndexes'
		}
	).render();
</aui:script>
thumbnail
Rohit Salecha, módosítva 13 év-val korábban

RE: AutoField example

Junior Member Bejegyzések: 50 Csatlakozás dátuma: 2011.02.21. Legújabb bejegyzések
Hey Lenart ,
Really appreciate your help on this. Thanks a Million !
Charaf faceofjock, módosítva 10 év-val korábban

RE: AutoField example

Junior Member Bejegyzések: 30 Csatlakozás dátuma: 2013.04.08. Legújabb bejegyzések
Thanks man emoticon
Umasankar Jeyaraj, módosítva 10 év-val korábban

RE: AutoField example

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.07.16. Legújabb bejegyzések
Hi,
Could you please provide me an example for Auto Fields with date field.

Thanks,
Umasankar
asif aftab, módosítva 9 év-val korábban

RE: AutoField example

Regular Member Bejegyzések: 123 Csatlakozás dátuma: 2013.09.02. Legújabb bejegyzések
Hi after a long time again I here to ask question,
now my question is
I am using auto field to create field dynamically and below is my code

<div id="email-fields" >
<div class="lfr-form-row lfr-form-row-inline" style="display: flex;">
<aui:input name="groupID1" type="hidden" />
<aui:input name="groupMemberName1" label="group-member-name" inlineLabel="true" style="width: 170px;"/>
<aui:input name="groupMemberEmail1" label="group-member-email" inlineLabel="true"/>
<aui:select name="groupMemberGender1" label="group-member-gender" inlineLabel="true" style="width: 134px;" >
<aui:option value="male" label="group-member-female" ></aui:option>
<aui:option value="female" label="group-member-male" ></aui:option>
</aui:select>
<aui:input name="groupMemberJob1" label="group-member-job" inlineLabel="true" style="width: 135px;"/>
<aui:button type="button" onclick="addDeleteGroupMembers(this)" name="addMemberToGroupLink1" value="add" class="field"/>
</div>
</div>

and my script

<aui:script>

AUI().use('liferay-auto-fields',function(A) {
new Liferay.AutoFields({
contentBox: '#email-fields',
fieldIndexes: '<portlet:namespace/>emailsIndexes'
}).render();
});
</aui:script>

Each and every thing is working properly and data is also added dynamically means row with all fields. The only problem is except button id all ids are changing.
I can't understand why button id is not changing. Other ids are changing.
Please help me to resolve this issue.
Thanks