diff --git a/client/client/src/billing-data/index.html b/client/client/src/billing-data/index.html index b6ff8cbb28..579cd885c9 100644 --- a/client/client/src/billing-data/index.html +++ b/client/client/src/billing-data/index.html @@ -39,6 +39,7 @@ field="$ctrl.client.bankEntityFk" fields="['name']" initial-data="$ctrl.client.bankEntityFk" + on-change="$ctrl.autofillBic()" search-function="{or: [{bic: {regexp: $search}}, {name: {regexp: $search}}]}" value-field="id" show-field="bic" diff --git a/client/client/src/billing-data/index.js b/client/client/src/billing-data/index.js index 4aba252bbb..e5c666a4a5 100644 --- a/client/client/src/billing-data/index.js +++ b/client/client/src/billing-data/index.js @@ -28,7 +28,6 @@ export default class Controller { if (this.hasPaymethodChanges()) shouldNotify = true; - this.autofillBic(); this.$scope.watcher.submit().then(() => { if (shouldNotify) this.notifyChanges(); @@ -87,10 +86,13 @@ export default class Controller { if (countryCode != 'ES') return; let json = encodeURIComponent(JSON.stringify(filter)); - this.client.bankEntityFk = undefined; this.$http.get(`/client/api/BankEntities?filter=${json}`).then(response => { - if (response.data && response.data[0]) + const hasData = response.data && response.data[0]; + + if (hasData) this.client.bankEntityFk = response.data[0].id; + else if (!hasData) + this.client.bankEntityFk = null; }); } } diff --git a/client/core/src/components/textfield/textfield.js b/client/core/src/components/textfield/textfield.js index 43a0a9bd8b..1155e5239e 100644 --- a/client/core/src/components/textfield/textfield.js +++ b/client/core/src/components/textfield/textfield.js @@ -15,24 +15,22 @@ export default class Textfield extends Input { this.hasMouseIn = false; this.input.addEventListener('keydown', () => { - if (!this.oldValue) { + if (!this.oldValue) this.saveOldValue(); - } }); this.input.addEventListener('keyup', e => { - if (e.key == "Escape") { + if (e.key == 'Escape') { this.value = this.oldValue; this.cancelled = true; e.stopPropagation(); } - if (e.key == "Escape" || e.key == "Enter") + if (e.key == 'Escape' || e.key == 'Enter') this.input.blur(); }); this.input.addEventListener('blur', () => { - if (this.onChange && !this.cancelled && - (this.oldValue && this.oldValue != this.value)) + if (this.onChange && !this.cancelled && (this.oldValue != this.value)) this.onChange(); else this.cancelled = false; diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index 9a80ab6694..5b0be47f5d 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -129,11 +129,9 @@ module.exports = Self => { }); function hasBic(err, done) { - Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.ibanRequired && !this.bankEntityFk) - err(); - done(); - }); + if (this.iban && !this.bankEntityFk) + err(); + done(); } Self.observe('before save', async function(ctx) {