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.
This commit is contained in:
chimp1984 2021-02-18 18:26:43 -05:00
parent 9ae76b621f
commit bc6a53d356
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
3 changed files with 21 additions and 5 deletions

View file

@ -76,7 +76,7 @@ public class InputTextField extends JFXTextField {
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 class InputTextField extends JFXTextField {
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() {

View file

@ -176,6 +176,11 @@ public class BsqSendView extends ActivatableView<GridPane, Void> implements BsqB
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 @@ public class BsqSendView extends ActivatableView<GridPane, Void> implements BsqB
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 @@ public class BsqSendView extends ActivatableView<GridPane, Void> implements BsqB
() -> {
receiversBtcAddressInputTextField.setText("");
btcAmountInputTextField.setText("");
receiversBtcAddressInputTextField.resetValidation();
btcAmountInputTextField.resetValidation();
});
}
} catch (BsqChangeBelowDustException e) {

View file

@ -16,6 +16,7 @@ public class JFXInputValidator extends ValidatorBase {
}
public void resetValidation() {
message.set(null);
hasErrors.set(false);
}