Skip to content

Commit 1672379

Browse files
author
wassx
committed
Added click event and delegate interface to handle on-the-fly date
changes
1 parent 852420b commit 1672379

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/gwt/material/design/client/ui/MaterialDatePicker.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@
2828

2929
public class MaterialDatePicker extends FocusPanel{
3030

31+
public interface MaterialDatePickerDelegate {
32+
void onCalendarClick(Date currDate);
33+
}
34+
3135
private HTMLPanel panel;
3236
private Date date;
3337
private String placeholder;
3438
private String id;
39+
private MaterialDatePickerDelegate delegate;
40+
3541
public MaterialDatePicker() {
3642

3743
}
@@ -45,6 +51,7 @@ protected void onAttach() {
4551
panel = new HTMLPanel("<input placeholder='"+placeholder+"' type='date' id='"+id+"' class='datepicker'>");
4652
this.add(panel);
4753
initDatePicker(id);
54+
onValueChange(id, this);
4855
}
4956

5057
public static native String getDatePickerValue(String id)/*-{
@@ -59,6 +66,22 @@ private static native void setDatePickerValue(String value, String id)/*-{
5966
public static native void initDatePicker(String id)/*-{
6067
$wnd.jQuery('#' + id).pickadate();
6168
}-*/;
69+
70+
native void onValueChange(String id, MaterialDatePicker picker) /*-{
71+
$wnd.jQuery('.picker__wrap').bind('click',function(){
72+
[email protected]::notifyDelegate()();
73+
});
74+
}-*/;
75+
76+
public void setDelegate(MaterialDatePickerDelegate del) {
77+
this.delegate = del;
78+
}
79+
80+
void notifyDelegate() {
81+
if(delegate != null) {
82+
delegate.onCalendarClick(getDate());
83+
}
84+
}
6285

6386

6487

0 commit comments

Comments
 (0)