Skip to content

Commit e48f832

Browse files
committed
Combobox Addins updates.
1 parent 5ad981a commit e48f832

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class MaterialComboBox<T> extends AbstractValueWidget<List<T>> implements
122122
protected List<T> values = new ArrayList<>();
123123
private Label label = new Label();
124124
private MaterialLabel errorLabel = new MaterialLabel();
125+
private MaterialLabel helperText = new MaterialLabel();
125126
protected MaterialWidget listbox = new MaterialWidget(Document.get().createSelectElement());
126127
private KeyFactory<T, String> keyFactory = new AllowBlankKeyFactory<>();
127128
private JsComboBoxOptions options = JsComboBoxOptions.create();
@@ -150,6 +151,8 @@ protected void onLoad() {
150151
addWidget(listbox);
151152
addWidget(label);
152153
addWidget(errorLabel);
154+
helperText.addStyleName("help-description");
155+
153156
errorLabel.setMarginTop(8);
154157
listbox.setGwtDisplay(Style.Display.BLOCK);
155158

@@ -341,7 +344,7 @@ public void clear() {
341344
final Iterator<Widget> it = iterator();
342345
while (it.hasNext()) {
343346
final Widget widget = it.next();
344-
if (widget != label && widget != errorLabel && widget != listbox) {
347+
if (widget != label && widget != errorLabel && widget != listbox && widget != helperText) {
345348
it.remove();
346349
}
347350
}
@@ -1381,4 +1384,10 @@ public AsyncWidgetMixin<MaterialComboBox, List<T>> getAsyncWidgetMixin() {
13811384
}
13821385
return asyncWidgetMixin;
13831386
}
1387+
1388+
@Override
1389+
public void setHelperText(String helperText) {
1390+
this.helperText.setText(helperText);
1391+
addWidget(this.helperText);
1392+
}
13841393
}

src/main/java/gwt/material/design/addins/client/inputmask/base/DateInputParser.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,33 @@ public void setValue(String format, Date value) {
4949
}
5050

5151
public boolean validate(String format) {
52-
if (valuebox.getText() != null && !valuebox.getText().isEmpty()
53-
&& valuebox.getMask() != null && format != null) {
54-
format = format.toLowerCase();
55-
String dateString = valuebox.getValueWithMask();
56-
String month = dateString.substring(format.indexOf("m"), format.indexOf("m") + 2);
57-
String day = dateString.substring(format.indexOf("d"), format.indexOf("d") + 2);
58-
String year = dateString.substring(format.indexOf("y"), format.lastIndexOf("y") + 1);
59-
60-
boolean validLeapYear = validateLeapYear(day, month, Integer.parseInt(year));
61-
if (!validLeapYear) {
62-
valuebox.setErrorText("Not a valid date");
52+
try {
53+
if (valuebox.getText() != null && !valuebox.getText().isEmpty()
54+
&& valuebox.getMask() != null && format != null) {
55+
format = format.toLowerCase();
56+
String dateString = valuebox.getValueWithMask();
57+
String month = dateString.substring(format.indexOf("m"), format.indexOf("m") + 2);
58+
String day = dateString.substring(format.indexOf("d"), format.indexOf("d") + 2);
59+
String year = dateString.substring(format.indexOf("y"), format.lastIndexOf("y") + 1);
60+
61+
boolean validLeapYear = validateLeapYear(day, month, Integer.parseInt(year));
62+
if (!validLeapYear) {
63+
valuebox.setErrorText("Not a valid date");
64+
}
65+
66+
boolean valid = validate(month, getMonthRegex(), getMothDoesNotMatchError())
67+
&& validate(day, getDayRegex(), getDayDoesNotMatchError())
68+
&& validate(year, getYearRegex(), getYearDoesNotMatchError())
69+
&& validLeapYear;
70+
71+
if (valid) {
72+
valuebox.clearStatusText();
73+
}
74+
75+
return valid;
6376
}
64-
65-
boolean valid = validate(month, getMonthRegex(), getMothDoesNotMatchError())
66-
&& validate(day, getDayRegex(), getDayDoesNotMatchError())
67-
&& validate(year, getYearRegex(), getYearDoesNotMatchError())
68-
&& validLeapYear;
69-
70-
if (valid) {
71-
valuebox.clearStatusText();
72-
}
73-
74-
return valid;
77+
} catch (Exception e) {
78+
valuebox.setErrorText("Not a valid date");
7579
}
7680
return false;
7781
}

0 commit comments

Comments
 (0)