Skip to content

Commit 7b2cc95

Browse files
committed
Merge pull request #34 from wassx/master
Improving api for resetting a textbox
2 parents 5b986f0 + a463512 commit 7b2cc95

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

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

2929
public class MaterialDatePicker extends FocusPanel{
3030

31+
/**
32+
* Delegate interface for handling picker events.
33+
*/
34+
public interface MaterialDatePickerDelegate {
35+
36+
/**
37+
* Called as soon as a click occurs on the calendar widget. !EXPERIMENTAL!
38+
* @param currDate which is currently selected.
39+
*/
40+
void onCalendarClick(Date currDate);
41+
}
42+
3143
private HTMLPanel panel;
3244
private Date date;
3345
private String placeholder;
3446
private String id;
47+
private MaterialDatePickerDelegate delegate;
48+
3549
public MaterialDatePicker() {
3650

3751
}
@@ -45,6 +59,7 @@ protected void onAttach() {
4559
panel = new HTMLPanel("<input placeholder='"+placeholder+"' type='date' id='"+id+"' class='datepicker'>");
4660
this.add(panel);
4761
initDatePicker(id);
62+
initClickHandler(id, this);
4863
}
4964

5065
public static native String getDatePickerValue(String id)/*-{
@@ -59,6 +74,27 @@ private static native void setDatePickerValue(String value, String id)/*-{
5974
public static native void initDatePicker(String id)/*-{
6075
$wnd.jQuery('#' + id).pickadate();
6176
}-*/;
77+
78+
native void initClickHandler(String id, MaterialDatePicker picker) /*-{
79+
$wnd.jQuery('.picker__wrap').bind('click',function(){
80+
[email protected]::notifyDelegate()();
81+
});
82+
}-*/;
83+
84+
/**
85+
* A delegate which implements handling of events from date picker.
86+
* @param delegate which will be notified on picker events.
87+
* @see MaterialDatePickerDelegate
88+
*/
89+
public void setDelegate(MaterialDatePickerDelegate delegate) {
90+
this.delegate = delegate;
91+
}
92+
93+
void notifyDelegate() {
94+
if(delegate != null) {
95+
delegate.onCalendarClick(getDate());
96+
}
97+
}
6298

6399

64100

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public void setValid() {
9191
txtBox.getElement().addClassName("valid");
9292
isValid = true;
9393
}
94+
95+
/**
96+
* Resets the textbox by removing its content and resetting visual state.
97+
*/
98+
public void clear() {
99+
txtBox.setText("");
100+
backToDefault();
101+
}
94102

95103
public void backToDefault() {
96104
txtBox.getElement().removeClassName("valid");

0 commit comments

Comments
 (0)