From 133d40a59a477435f30d911cdf0dfa7d39fe0b97 Mon Sep 17 00:00:00 2001 From: beingindot Date: Thu, 7 Nov 2019 13:04:33 +0530 Subject: [PATCH] Added check for empty validation This commit is for github issue #3458 and #3459 check added for moneybeam and national bank transfer --- .../bisq/core/util/validation/InputValidator.java | 3 ++- .../desktop/components/paymentmethods/BankForm.java | 10 +++++----- .../components/paymentmethods/GeneralBankForm.java | 13 ++++++++----- .../components/paymentmethods/MoneyBeamForm.java | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/bisq/core/util/validation/InputValidator.java b/core/src/main/java/bisq/core/util/validation/InputValidator.java index 31125283fc7..cc9a27825fa 100644 --- a/core/src/main/java/bisq/core/util/validation/InputValidator.java +++ b/core/src/main/java/bisq/core/util/validation/InputValidator.java @@ -28,7 +28,8 @@ public ValidationResult validate(String input) { } protected ValidationResult validateIfNotEmpty(String input) { - if (input == null || input.length() == 0) + //trim added to avoid empty input + if (input == null || input.trim().length() == 0) return new ValidationResult(false, Res.get("validation.empty")); else return new ValidationResult(true); diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BankForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BankForm.java index f9b2d13127f..26ee2278944 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/BankForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/BankForm.java @@ -240,28 +240,28 @@ public void addFormForAddAccount() { bankNameInputTextField = addInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name")); bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - bankAccountPayload.setBankName(newValue); + bankAccountPayload.setBankName(newValue.trim()); updateFromInputs(); }); bankIdInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel("")); bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - bankAccountPayload.setBankId(newValue); + bankAccountPayload.setBankId(newValue.trim()); updateFromInputs(); }); branchIdInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel("")); branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - bankAccountPayload.setBranchId(newValue); + bankAccountPayload.setBranchId(newValue.trim()); updateFromInputs(); }); accountNrInputTextField = addInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel("")); accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - bankAccountPayload.setAccountNr(newValue); + bankAccountPayload.setAccountNr(newValue.trim()); updateFromInputs(); }); @@ -381,7 +381,7 @@ private void addHolderNameAndId() { holderNameInputTextField = tuple.first; holderNameInputTextField.setMinWidth(250); holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - bankAccountPayload.setHolderName(newValue); + bankAccountPayload.setHolderName(newValue.trim()); updateFromInputs(); }); holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty()); diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralBankForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralBankForm.java index 9ea45fd7b7c..97f422964e8 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralBankForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/GeneralBankForm.java @@ -117,7 +117,7 @@ void validateInput(String countryCode) { bankNameInputTextField.setValidator(null); bankIdInputTextField.setValidator(null); branchIdInputTextField.setValidator(null); - accountNrInputTextField.setValidator(null); + accountNrInputTextField.setValidator(inputValidator); nationalAccountIdInputTextField.setValidator(null); } } @@ -142,20 +142,20 @@ void autoFillAccountTextFields(CountryBasedPaymentAccountPayload paymentAccountP if (countryCode == null) countryCode = ""; if (BankUtil.isBankIdRequired(countryCode)) { - bankId = bankIdInputTextField.getText(); + bankId = bankIdInputTextField.getText().trim(); if (bankId.length() > 9) bankId = StringUtils.abbreviate(bankId, 9); } else if (BankUtil.isBranchIdRequired(countryCode)) { - bankId = branchIdInputTextField.getText(); + bankId = branchIdInputTextField.getText().trim(); if (bankId.length() > 9) bankId = StringUtils.abbreviate(bankId, 9); } else if (BankUtil.isBankNameRequired(countryCode)) { - bankId = bankNameInputTextField.getText(); + bankId = bankNameInputTextField.getText().trim(); if (bankId.length() > 9) bankId = StringUtils.abbreviate(bankId, 9); } - String accountNr = accountNrInputTextField.getText(); + String accountNr = accountNrInputTextField.getText().trim(); if (accountNr.length() > 9) accountNr = StringUtils.abbreviate(accountNr, 9); @@ -200,7 +200,10 @@ boolean getValidationResult(boolean result, String countryCode, String bankName, if (BankUtil.isNationalAccountIdRequired(countryCode)) result = result && nationalAccountIdInputTextField.getValidator().validate(nationalAccountId).isValid; + } else { // only account number not empty validation + result = result && accountNrInputTextField.getValidator().validate(accountNr).isValid; } + return result; } } diff --git a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyBeamForm.java b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyBeamForm.java index 1659b16a018..f372ceb73b3 100644 --- a/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyBeamForm.java +++ b/desktop/src/main/java/bisq/desktop/components/paymentmethods/MoneyBeamForm.java @@ -62,7 +62,7 @@ public void addFormForAddAccount() { accountIdInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.moneyBeam.accountId")); accountIdInputTextField.setValidator(validator); accountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { - account.setAccountId(newValue); + account.setAccountId(newValue.trim()); updateFromInputs(); }); @@ -75,7 +75,7 @@ public void addFormForAddAccount() { @Override protected void autoFillNameTextField() { - setAccountNameWithString(accountIdInputTextField.getText()); + setAccountNameWithString(accountIdInputTextField.getText().trim()); } @Override