3

ボタンをクリックすると入力フィールドのセットを複製する必要があります。必要な回数だけ。

この機能は、LIFeray にあるものと同じです。

「コントロール パネル -> ユーザー」に移動し、任意のユーザーをクリックします。

ページの右側、[識別情報] の下。「住所、電話番号」をクリックします。

プラス記号 ([追加] ボタン) をクリックすると、入力フィールドのセットが複製されます。

これが私の要件のために行ったコードです。

入力フィールドのコード:

<input class="date-pick" readonly="readonly" id="<portlet:namespace/>fromDate1"   type="text" onchange="showDate()"

     name="<portlet:namespace/>fromDate1" value="" />" >

日付の値を使用する JavaScript:

function showDate()
  {
   alert(document.getElementById("<portlet:namespace/>fromDate1"));
  }

上記のテキスト ボックスで datepicker をバインドする jQuery 関数:

jQuery(function(){
  jQuery('.date-pick').datepicker({autoFocusNextInput: true});
});

フォームフィールドの重複行を作成する Liferay.Autofields 関数:

jQuery(
  function () {
        new Liferay.AutoFields(
                    {
                          container: '#<portlet:namespace />webFields',
                          baseRows: '#<portlet:namespace />webFields > .lfr-form-row',
                          fieldIndexes: '<portlet:namespace />formFieldsIndexes',
                          onAdd: function(newField) {
                                      alert('This field got added.');
                                      jQuery('.date-pick').datepicker({autoFocusNextInput: true});
                                },

                          onRemove: function() {
                                      alert('The last field was removed.');
                                }
                    }
        );
  }

);

入力フィールドの元のセットでは、日付ピッカーは適切に機能します。しかし、プラス記号 ([追加] ボタン) をクリックした後に生成された入力フィールドのセットでは、日付ピッカーは機能しません。

また、入力フィールドの名前が動的に変更されるため、入力フィールドの値を使用する際に問題に直面しています (javascript 関数 showDate() を参照)。

誰かがこれに取り組んだか、何か考えがあります。それなら助けてください

4

2 に答える 2

1

解決しました。このスレッドに再び感謝します -

jQuery UI の日付ピッカーが動的 DOM で機能しないのはなぜですか?

于 2011-06-15T08:04:08.300 に答える
0

It appears that the AutoFields plugin is not compatible with the DatePicker plugin. The issue lies in that the JavaScript events responsible for the DatePicker widget are not getting copied correctly on the replicated fields.

I suppose you could fix that in the "onAdd" event, but I am at a loss for how you would implement that piece.

于 2011-06-14T17:02:52.937 に答える