ボタンをクリックすると入力フィールドのセットを複製する必要があります。必要な回数だけ。
この機能は、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() を参照)。
誰かがこれに取り組んだか、何か考えがあります。それなら助けてください