Bellow is an example:
alert('not "using" any modules, Im fired right away');
alert('"using" aui-io, Im fired when its ready');
So we make sure never to define a function inside of an aui-script block that has a "use" attribute, unless we're creating another module to be used.
But then how do you define a function that uses a module?
Luckily, we can use Liferay.provide.
For simplicity here I have used two field which will indicated the checked and unchecked value of checkboks and can easily get this value on action class, like bellow:
<aui:input name="addCommIds" type="hidden" value="" />
<aui:input name="removeCommIds" type="hidden" value="" />
Bellow given the aui:script code:
Liferay.provide(
window,
'saveEntry',
function() {
document.fm.addCommIds.value = Liferay.Util.listCheckedExcept(document.fm, "allRowIds");
document.fm.removeCommIds.value = Liferay.Util.listUncheckedExcept(document.fm, "allRowIds");
submitForm(document.fm);
},
['liferay-util-list-fields']
);
NB: listCheckedExcept is a javascript function
we can simply call this function as bellow:
<aui:button onClick="<%= renderResponse.getNamespace() + "saveEntry();" %>"value="save" />
Source