假設一些「模板」 <aui:select>
您的形式類似於中存在:
<aui:select id="elementIdPrefix0" name="elementIdPrefix0" label="Number" showEmptyOption='true' > <!-- options go here --></aui:select>
在你auto-fields
,你就需要爲clone
事件提供on
事件偵聽器。在回調中,您可以從剛剛創建的行容器節點中查找<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');
)。
我還包括你有[問](http://www.liferay.com/community/forums//message_boards/message/38630011?_19_redirect=http%3A%2F%2Fwww.liferay.com% 2Fcommunity%2Fforums%2F-%2Fmessage_boards%2Fsearch%3F_19_keywords%3Dautofields%26_19_searchCategoryId%3D0%26_19_breadcrumbsCategoryId%3D0%26_19_redirect%3Dhttp%253A%252F%252Fwww.liferay.com%252Fcommunity%252Fforums%252F-%252Fmessage_boards%252Fmessage%252F15088039% 26_19_formDate%3D1402068697228)生命線論壇上的問題。 – Origineil
字段是表單的一部分嗎? – Origineil
是的Origineil,這些字段是表格的一部分 –