RE: AutoFields and onChange method

Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Hi.
I am developing a form on Liferay 7.1 which has aui:select. I want to use Liferay AutoFields, and the use the JQuery onchange method.
My problem is that the onChange method is only triggered by the select that I've created by code, but not by the aui:selects that are created with the Liferay Auto Fields. Liferay Auto Fields appears to work fine, as the new fields are created, and onChange methods looks fine as it works for the first select.
Anyone can give an idea about this? I am very lost.

- Select method

<aui:select id="select1" name="select1">
	<aui:option label="1" value="1"></aui:option>
	<aui:option label="2" value="2"></aui:option>
	<aui:option label="3" value="3"></aui:option>
</aui:select>


- On Change method


<script>
$('select').on('change', function() {	
console.log(this);
});
</script>


Any help would be very appreciated. Thanks in advance
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,
You can try  triggering event on class rather the element or id as in autofield there will be multiple field getting clone ,  try using below code
[code]$(document).on('click', '.selectclass', function(){});
Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Hi.

Thanks for your help, Following your instructions, I've changed the method and it works. Thanks again!

Regards