Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java @ 7745:1d6b957d8953
issue1549: Add live-validation to wsplgen to-field.
Unfortunately, controlling the displayed message proved difficult due
to mixed error/validation-handling code. It shows wrong format message
for now.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 11 Feb 2014 12:37:16 +0100 |
parents | ea9eef426962 |
children | 316a9eeb0836 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java Fri Feb 07 15:48:43 2014 +0100 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java Tue Feb 11 12:37:16 2014 +0100 @@ -45,6 +45,9 @@ * distance.*/ public static final String FIELD_WIDTH = "step"; + /** Whether or not negative 'to' values are allowed. */ + protected boolean negativeToAllowed = true; + /** The textboxes */ protected FloatItem fromItem; protected FloatItem toItem; @@ -153,6 +156,10 @@ stepItem.setValue(f.format(steps)); } + public void setNegativeToAllowed(boolean isAllowed) { + negativeToAllowed = isAllowed; + } + public boolean validateForm() { try { @@ -171,6 +178,9 @@ * there are values that doesn't represent a valid float, an error is * displayed. * + * Also if negativeToAllowed is false, an error is registered if + * the 'to' field contains a negative value. + * * @param item The FormItem. */ @SuppressWarnings("unchecked") @@ -187,12 +197,14 @@ @SuppressWarnings("rawtypes") Map errors = getErrors(); + Double d = 0d; + try { if (v == null) { throw new NumberFormatException("empty"); } - f.parse(v); + d = f.parse(v); errors.remove(item.getFieldName()); } @@ -204,6 +216,17 @@ valid = false; } + if (negativeToAllowed == false + && item.getFieldName().equals(FIELD_TO) && d < 0d) { + errors.put(item.getFieldName(), MESSAGES.toShouldNotBeNegative()); + + item.setValue(""); + + item.focusInItem(); + + valid = false; + } + setErrors(errors, true); return valid;