Skip to content

Commit

Permalink
Improve resetValidation method to reset validation result
Browse files Browse the repository at this point in the history
If text field is empty we apply ValidationResult(true), otherwise we apply
the validate result with the text and the given validator.
  • Loading branch information
chimp1984 committed Feb 18, 2021
1 parent 9ae76b6 commit bc6a53d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public InputTextField() {

validationResult.addListener((ov, oldValue, newValue) -> {
if (newValue != null) {
resetValidation();
jfxValidationWrapper.resetValidation();
if (!newValue.isValid) {
if (!newValue.errorMessageEquals(oldValue)) { // avoid blinking
validate(); // ensure that the new error message replaces the old one
Expand Down Expand Up @@ -118,6 +118,13 @@ public InputTextField(double inputLineExtension) {

public void resetValidation() {
jfxValidationWrapper.resetValidation();

String input = getText();
if (input.isEmpty()) {
validationResult.set(new InputValidator.ValidationResult(true));
} else {
validationResult.set(validator.validate(input));
}
}

public void refreshValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ protected void activate() {
setSendBtcGroupVisibleState(false);
bsqBalanceUtil.activate();

receiversAddressInputTextField.resetValidation();
amountInputTextField.resetValidation();
receiversBtcAddressInputTextField.resetValidation();
btcAmountInputTextField.resetValidation();

sendBsqButton.setOnAction((event) -> onSendBsq());
bsqInputControlButton.setOnAction((event) -> onBsqInputControl());
sendBtcButton.setOnAction((event) -> onSendBtc());
Expand Down Expand Up @@ -309,12 +314,11 @@ private void onSendBsq() {
bsqFormatter,
btcFormatter,
() -> {
receiversAddressInputTextField.setValidator(null);
receiversAddressInputTextField.setText("");
receiversAddressInputTextField.setValidator(bsqAddressValidator);
amountInputTextField.setValidator(null);
amountInputTextField.setText("");
amountInputTextField.setValidator(bsqValidator);

receiversAddressInputTextField.resetValidation();
amountInputTextField.resetValidation();
});
} catch (BsqChangeBelowDustException e) {
String msg = Res.get("popup.warning.bsqChangeBelowDustException", bsqFormatter.formatCoinWithCode(e.getOutputValue()));
Expand Down Expand Up @@ -444,6 +448,10 @@ private void onSendBtc() {
() -> {
receiversBtcAddressInputTextField.setText("");
btcAmountInputTextField.setText("");

receiversBtcAddressInputTextField.resetValidation();
btcAmountInputTextField.resetValidation();

});
}
} catch (BsqChangeBelowDustException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected void eval() {
}

public void resetValidation() {
message.set(null);
hasErrors.set(false);
}

Expand Down

0 comments on commit bc6a53d

Please sign in to comment.