fix: display IsIBAN message for country validators if Unparseable
This commit is contained in:
parent
a45064696d
commit
983bb2fd23
1 changed files with 11 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable max-classes-per-file */
|
||||
|
||||
import { localize } from '@lion/localize';
|
||||
import { Validator } from '@lion/form-core';
|
||||
import { Unparseable, Validator } from '@lion/form-core';
|
||||
import { isValidIBAN } from 'ibantools';
|
||||
|
||||
let loaded = false;
|
||||
|
|
@ -150,7 +150,10 @@ export class IsCountryIBAN extends IsIBAN {
|
|||
*/
|
||||
static async getMessage(data) {
|
||||
await loadTranslations();
|
||||
return localize.msg('lion-validate+iban:error.IsCountryIBAN', data);
|
||||
// If modelValue is Unparseable, the IsIBAN message is the more appropriate feedback
|
||||
return data?.modelValue instanceof Unparseable
|
||||
? localize.msg('lion-validate+iban:error.IsIBAN', data)
|
||||
: localize.msg('lion-validate+iban:error.IsCountryIBAN', data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,10 +199,12 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|||
const _data = {
|
||||
...data,
|
||||
userSuppliedCountryCode:
|
||||
typeof data?.modelValue === 'string'
|
||||
? data?.modelValue.slice(0, 2)
|
||||
: data?.modelValue.viewValue.slice(0, 2),
|
||||
typeof data?.modelValue === 'string' ? data?.modelValue.slice(0, 2) : '',
|
||||
};
|
||||
return localize.msg('lion-validate+iban:error.IsNotCountryIBAN', _data);
|
||||
|
||||
// If modelValue is Unparseable, the IsIBAN message is the more appropriate feedback
|
||||
return data?.modelValue instanceof Unparseable
|
||||
? localize.msg('lion-validate+iban:error.IsIBAN', _data)
|
||||
: localize.msg('lion-validate+iban:error.IsNotCountryIBAN', _data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue