private void checkBlurHandler() { if (blurReg != null || !isAttached()) return; if (validateAsInt || validateAsDouble) { blurReg = addBlurHandler(blur -> validate()); } }
public void setValidateAsDouble(boolean validateAsDouble) { this.validateAsDouble = validateAsDouble; checkBlurHandler(); }
private boolean validate() { boolean isValid = isInputValid(input.getElement()); if (isValid) { String s = getValue(); if (!Empty.is(s)) { if (validateAsInt) { isValid = INT_REGEX.test(s); } if (validateAsDouble) { isValid = DOUBLE_REGEX0.test(s); if (!isValid) isValid = DOUBLE_REGEX1.test(s); } } } if (isValid) { this.removeStyleName(STYLE_ERRORCONTAIN); } else { this.addStyleName(STYLE_ERRORCONTAIN); } return isValid; }
public JQMNumber(String text) { super(text); setType("number"); }
@Override public void setValue(String value, boolean fireEvents) { super.setValue(value, fireEvents); validate(); }
public Double getDoubleValue() { if (!validate()) return null; Double rslt = null; String s = getValue(); try { rslt = Double.parseDouble(s); } catch (Exception e) { if (s != null) { if (s.indexOf('.') >= 0) s = s.replaceAll("\\.", ","); else if (s.indexOf(',') >= 0) s = s.replaceAll("\\,", "."); } try { rslt = Double.parseDouble(s); } catch (Exception e1) { // nothing, can continue } } return rslt; } }
public JQMNumber(String text) { super(text); setType("number"); }
public void setValidateAsInt(boolean validateAsInt) { this.validateAsInt = validateAsInt; checkBlurHandler(); }
@Override protected void onLoad() { super.onLoad(); checkBlurHandler(); }