aui的验证器:在Liferay中使用autofield选择

时间:2014-06-06 11:34:20

标签: jquery liferay alloy-ui liferay-aui autofield

我想知道如何为aui编写验证器:select字段在Autofield类别中。

这是我的代码结构:

for( loop total number of items)
{
// CREATE aui select, and aui inputs by appending the index
}

Autofields的功能没有问题。通过循环遍历我的项目集合,我可以在查看表单时创建重复的条目,并且在创建"创建时也没有问题。使用liferay提供PLUS图标的表格。

我在容器中有aui:select元素,它将根据Autofield功能进行复制。如何为此aui:select元素提供验证器。 ?

1 个答案:

答案 0 :(得分:1)

假设一些&#34;模板&#34; <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');之类的选择器。

相关问题