0

Autofield カテゴリにある aui:select フィールドのバリデータを作成する方法を知りたいと思いました。

これは私のコードの構造です:

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

Autofields の機能に問題はありません。アイテム コレクションをループしてフォームを表示しているときに、重複したエントリを作成できます。ライフレイが提供する PLUS アイコンを使用してフォームを「作成」している間も問題はありません。

コンテナーに aui:select 要素があり、これは Autofield 機能に従って複製されます。この aui:select 要素のバリデータを提供するにはどうすればよいですか。?

4

1 に答える 1

1

次のような「テンプレート」<aui:select>がフォーム内に存在すると仮定します。

<aui:select id="elementIdPrefix0" name="elementIdPrefix0" label="Number" showEmptyOption='true' > <!--  options go here  --></aui:select>

では、イベントのイベント リスナーauto-fieldsを提供する必要があります。コールバック内で、作成されたばかりの行コンテナー ノード内から参照します(パラメーターとしてコールバックに渡されます)。onclone<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');を使用する必要があります。

于 2014-06-09T15:00:26.653 に答える