次の2つのケースを処理する必要があります。
- 選択した日付が変更された場合:
onSelect
イベントを使用してボタンのタイトル属性を変更します
- 初期レンダリング時:残念ながら、datepickerはウィジェットファクトリを(まだ)実装していないため、イベントは発生しません。ウィジェットが初期化された後、
create
title属性を手動で更新する必要があります。
ピッカーのデフォルトの日付をフィールドの初期値に設定することを忘れないでください。そうしないと、デフォルトで選択される日付は「今日」になります。
このようなもの:
// as you have several instances, loops through them
$(".deadline_picker_on").each(function() {
var dt = $(this);
dt.datepicker({
showOn: "button",
buttonText: '',
// set the default date to the value of the field
defaultDate: dt.val(),
duration: 100,
dateFormat: 'yy-mm-dd',
showOptions: {
direction: 'right'
},
onSelect: function(dateText, inst) {
// on data selection, change the title attribute of the button
$(this).next().attr('title', dateText);
}
})
// get the button (next element)
.next()
// set the title attribute with the formatted initial date from the picker
.attr('title', $.datepicker.formatDate('yy-mm-dd', dt.datepicker('getDate')));
});