Assuming some "template" <aui:select>
exists within your form similar to:
<aui:select id="elementIdPrefix0" name="elementIdPrefix0" label="Number" showEmptyOption='true' > <!-- options go here --></aui:select>
In your auto-fields
, you would need to provide an on
event listener for the clone
event. Within the callback you lookup the <aui:select>
from within the row container node that was just created (passed into the callback as a parameter).
<script>
AUI().use('liferay-auto-fields', 'aui-form-validator', function(A){
//Setup rules
var elementIdPrefix = '<portlet:namespace />elementIdPrefix',
myRules = {},
rulesRepository = {};
rulesRepository[elementIdPrefix] = {required:true};
myRules [elementIdPrefix + '0'] = rulesRepository[elementIdPrefix];
//Define validator
var validator = new A.FormValidator({
boundingBox: '#<portlet:namespace />myForm',
rules: myRules
});
new Liferay.AutoFields({
contentBox: '#my-fields',
fieldIndexes: '<portlet:namespace />indexes',
on: {
'clone': function(container){
//Lookup the clone
AUI().all('[name^=<portlet:namespace />elementId]').each(function(node, index){
if(container.row.contains(node)){
console.log("Assign to " + node.get('id'))
//inject the rules
myRules [node.get('id')] = rulesRepository[elementIdPrefix]
}
})
}
}
}).render();
});
</script>
Ideally, you should be able to use a child selector to get the node from within the clone
container. I had to provide a different way since I couldn't get that method to work. The reason I can use my approach is due to the fact that I know what the elementIdPrefix
is. For the sake of being able to provide an example, I went ahead and took advantage of this fact.
For a more dynamic approach, a selector such as myNode.one('> selectorString');
would have to be used.