前回、jquery.ui.datepicker.mobile.js で
<input type="date" に対して、Wicket の DateTextFiled コンポーネントを適用させようと
して、諦めて TextField<String> を使う方法を示したが、
DateTextFiled を適用させる抜け道がある。
org.apache.wicket.Component.checkComponentTagAttribute で落ちないように
する方法である。checkComponentTagAttribute が、onComponentTag で呼ばれているので、onComponentTag をオーバライドして実行しないようにする。
final DateTextField deploydate = new DateTextField("deploydate",new Model<Date>()){
@Override
protected void onComponentTag(ComponentTag tag){
tag.put("id",getId());
tag.put("type","true");
tag.put("data-type","date");
tag.put("class","ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c");
}
};
しかし、ここで初期値、日付をonComponentTag で、
tag.put("value","2011/11/03");
としても、現在日になってしまう。
デフォルト日付を指定するには、jquery.ui.datepicker.mobile.js の最後、以下を書き換えて、、、
(修正前)
//bind to pagecreate to automatically enhance date inputs
$( ".ui-page" ).live( "pagecreate", function(){
$( "input[type='date'], input:jqmData(type='date')" ).each(function(){
$(this).after( $( "<div />" ).datepicker({ altField: "#" + $(this).attr( "id" ), showOtherMonths: true }) );
});
});
(修正後)
//bind to pagecreate to automatically enhance date inputs
$(".ui-page").live( "pagecreate", function(){
$("input[type='date'], input:jqmData(type='date')").each(function(){
var thisid = "#" + $(this).attr( "id" );
if ( $(thisid).val().length > 0 ) {
$(this).after( $( "<div />" ).datepicker({
altField: thisid,
showOtherMonths: true,
defaultDate: $(thisid).val(),
}));
} else {
$(this).after( $("<div />").datepicker({ altField: thisid, showOtherMonths: true }));
}
});
});
これで、onComponentTag の中で
tag.put("value","2011/09/12");
とすれば、初期日付を指定できる。