From bc6a53d356e68700e48e9b99cbd492c77e600338 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 18 Feb 2021 18:26:43 -0500 Subject: [PATCH] Improve resetValidation method to reset validation result If text field is empty we apply ValidationResult(true), otherwise we apply the validate result with the text and the given validator. --- .../bisq/desktop/components/InputTextField.java | 9 ++++++++- .../main/dao/wallet/send/BsqSendView.java | 16 ++++++++++++---- .../util/validation/JFXInputValidator.java | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/InputTextField.java b/desktop/src/main/java/bisq/desktop/components/InputTextField.java index 064f7d0f8ba..536813a1a01 100644 --- a/desktop/src/main/java/bisq/desktop/components/InputTextField.java +++ b/desktop/src/main/java/bisq/desktop/components/InputTextField.java @@ -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 @@ -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() { diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java index 7450bca5668..11293867136 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/send/BsqSendView.java @@ -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()); @@ -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())); @@ -444,6 +448,10 @@ private void onSendBtc() { () -> { receiversBtcAddressInputTextField.setText(""); btcAmountInputTextField.setText(""); + + receiversBtcAddressInputTextField.resetValidation(); + btcAmountInputTextField.resetValidation(); + }); } } catch (BsqChangeBelowDustException e) { diff --git a/desktop/src/main/java/bisq/desktop/util/validation/JFXInputValidator.java b/desktop/src/main/java/bisq/desktop/util/validation/JFXInputValidator.java index bf10fef8548..135cf58713b 100644 --- a/desktop/src/main/java/bisq/desktop/util/validation/JFXInputValidator.java +++ b/desktop/src/main/java/bisq/desktop/util/validation/JFXInputValidator.java @@ -16,6 +16,7 @@ protected void eval() { } public void resetValidation() { + message.set(null); hasErrors.set(false); }