次のような「テンプレート」<aui:select>
がフォーム内に存在すると仮定します。
<aui:select id="elementIdPrefix0" name="elementIdPrefix0" label="Number" showEmptyOption='true' > <!-- options go here --></aui:select>
では、イベントのイベント リスナーauto-fields
を提供する必要があります。コールバック内で、作成されたばかりの行コンテナー ノード内から参照します(パラメーターとしてコールバックに渡されます)。on
clone
<aui:select>
<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>
clone
理想的には、子セレクターを使用してコンテナー内からノードを取得できる必要があります。その方法を機能させることができなかったため、別の方法を提供する必要がありました。私が私のアプローチを使用できる理由は、私がそれが何であるかを知っているという事実によるものelementIdPrefix
です. 例を提供できるようにするために、先に進んでこの事実を利用しました。
より動的なアプローチでは、 のようなセレクターmyNode.one('> selectorString');
を使用する必要があります。