chore: allow array for IsNotCountryIBAN
This commit is contained in:
parent
1d52585a6e
commit
a45064696d
18 changed files with 85 additions and 54 deletions
|
|
@ -8,7 +8,7 @@ Its purpose is to provide a way for users to fill in an IBAN (International Bank
|
|||
```js script
|
||||
import { html } from 'lit-html';
|
||||
import { loadDefaultFeedbackMessages } from '@lion/validate-messages';
|
||||
import { IsCountryIBAN } from './src/validators.js';
|
||||
import { IsCountryIBAN, IsNotCountryIBAN } from './src/validators.js';
|
||||
|
||||
import './lion-input-iban.js';
|
||||
|
||||
|
|
@ -98,11 +98,13 @@ To get the default feedback message for this default validator, use `loadDefault
|
|||
|
||||
In the example below, we show how to use an additional validator that blocks IBANs from certain countries.
|
||||
|
||||
You can pass a single string value, or an array of strings.
|
||||
|
||||
```js preview-story
|
||||
export const blacklistedCountry = () => html`
|
||||
<lion-input-iban
|
||||
.modelValue=${'RO89RZBR6997372848645577'}
|
||||
.validators=${([new IsNotCountryIBAN('RO')], [new IsNotCountryIBAN('ES')])}
|
||||
.modelValue=${'DE89370400440532013000'}
|
||||
.validators=${[new IsNotCountryIBAN(['RO', 'NL'])]}
|
||||
name="iban"
|
||||
label="IBAN"
|
||||
></lion-input-iban>
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ export class IsCountryIBAN extends IsIBAN {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {?} [value]
|
||||
* @param {string} value
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
execute(value) {
|
||||
|
|
@ -160,18 +160,25 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {?} [value]
|
||||
* @param {string} value
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
execute(value) {
|
||||
let isInvalid = false;
|
||||
const notIBAN = super.execute(value);
|
||||
if (value.slice(0, 2) === this.param) {
|
||||
return true;
|
||||
|
||||
if (typeof this.param === 'string') {
|
||||
if (value.slice(0, 2) === this.param) {
|
||||
isInvalid = true;
|
||||
}
|
||||
} else if (Array.isArray(this.param)) {
|
||||
isInvalid = this.param.some(country => value.slice(0, 2) === country);
|
||||
}
|
||||
|
||||
if (notIBAN) {
|
||||
return true;
|
||||
isInvalid = true;
|
||||
}
|
||||
return false;
|
||||
return isInvalid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,6 +193,13 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|||
*/
|
||||
static async getMessage(data) {
|
||||
await loadTranslations();
|
||||
return localize.msg('lion-validate+iban:error.IsNotCountryIBAN', data);
|
||||
const _data = {
|
||||
...data,
|
||||
userSuppliedCountryCode:
|
||||
typeof data?.modelValue === 'string'
|
||||
? data?.modelValue.slice(0, 2)
|
||||
: data?.modelValue.viewValue.slice(0, 2),
|
||||
};
|
||||
return localize.msg('lion-validate+iban:error.IsNotCountryIBAN', _data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ describe('IBAN validation', () => {
|
|||
const validator = new IsIBAN();
|
||||
expect(validator.execute('NL17INGB0002822608')).to.be.false;
|
||||
expect(validator.execute('DE89370400440532013000')).to.be.false;
|
||||
expect(validator.execute('foo')).to.be.true;
|
||||
});
|
||||
|
||||
it('provides IsCountryIBAN to limit IBANs from specific countries', () => {
|
||||
|
|
@ -17,7 +18,7 @@ describe('IBAN validation', () => {
|
|||
expect(nlValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
expect(deValidator.execute('DE89370400440532013000')).to.be.false;
|
||||
expect(nlValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
expect(nlValidator.execute('foo')).to.be.true;
|
||||
expect(deValidator.execute('NL17INGB0002822608')).to.be.true;
|
||||
});
|
||||
|
||||
it('provides IsNotCountryIBAN to prevent IBANs from specific countries', () => {
|
||||
|
|
@ -28,4 +29,18 @@ describe('IBAN validation', () => {
|
|||
expect(nlValidator.execute('DE89370400440532013000')).to.be.false;
|
||||
expect(deValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
});
|
||||
|
||||
it('accepts an array for IsNotCountryIBAN to prevent IBANs from multiple countries', () => {
|
||||
const nlValidator = new IsNotCountryIBAN(['NL', 'FR']);
|
||||
const deValidator = new IsNotCountryIBAN(['DE', 'SK']);
|
||||
expect(nlValidator.execute('NL17INGB0002822608')).to.be.true;
|
||||
expect(nlValidator.execute('FR1420041010050500013M02606')).to.be.true;
|
||||
expect(nlValidator.execute('DE89370400440532013000')).to.be.false;
|
||||
expect(nlValidator.execute('SK3112000000198742637541')).to.be.false;
|
||||
|
||||
expect(deValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
expect(deValidator.execute('FR1420041010050500013M02606')).to.be.false;
|
||||
expect(deValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
expect(deValidator.execute('SK3112000000198742637541')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Австрийски}\n' +
|
||||
'BE {Белгийски}\n' +
|
||||
'CZ {Чешки}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Нидерландски}\n' +
|
||||
'PL {Полски}\n' +
|
||||
'RO {Румънски}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} не е позволено.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Rakušan}\n' +
|
||||
'BE {Belgičan}\n' +
|
||||
'CZ {Čech}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Holanďan}\n' +
|
||||
'PL {Polák}\n' +
|
||||
'RO {Rumun}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} není povoleno.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName} ein.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Österreichisch}\n' +
|
||||
'BE {Belgisch}\n' +
|
||||
'CZ {Tschechisch}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Niederländisch}\n' +
|
||||
'PL {Polnisch}\n' +
|
||||
'RO {Rumänisch}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} ist nicht erlaubt.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,20 +16,20 @@ export default {
|
|||
'RO {Romanian}\n' +
|
||||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Austrian}\n' +
|
||||
'BE {Belgian}\n' +
|
||||
'CZ {Czech}\n' +
|
||||
'DE {German}\n' +
|
||||
'ES {Spanish}\n' +
|
||||
'FR {French}\n' +
|
||||
'HU {Hungarian}\n' +
|
||||
'IT {Italian}\n' +
|
||||
'NL {Dutch}\n' +
|
||||
'PL {Polish}\n' +
|
||||
'RO {Romanian}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} is not allowed.',
|
||||
},
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'AT {Austrian}\n' +
|
||||
'BE {Belgian}\n' +
|
||||
'CZ {Czech}\n' +
|
||||
'DE {German}\n' +
|
||||
'ES {Spanish}\n' +
|
||||
'FR {French}\n' +
|
||||
'HU {Hungarian}\n' +
|
||||
'IT {Italian}\n' +
|
||||
'NL {Dutch}\n' +
|
||||
'PL {Polish}\n' +
|
||||
'RO {Romanian}\n' +
|
||||
'other {{params}}\n' +
|
||||
'} {fieldName} is not allowed.',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'}.',
|
||||
IsNotCountryIBAN:
|
||||
'{fieldName} {params, select,\n' +
|
||||
'{fieldName} {userSuppliedCountryCode, select,\n' +
|
||||
'AT {Austriaco}\n' +
|
||||
'BE {Belga}\n' +
|
||||
'CZ {Checo}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Neerlandés}\n' +
|
||||
'PL {Polaco}\n' +
|
||||
'RO {Rumano}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} no se permite.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} valide.',
|
||||
IsNotCountryIBAN:
|
||||
'{fieldName} {params, select,\n' +
|
||||
'{fieldName} {userSuppliedCountryCode, select,\n' +
|
||||
'AT {autrichien}\n' +
|
||||
'BE {belge}\n' +
|
||||
'CZ {tchèque}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {néerlandais}\n' +
|
||||
'PL {polonais}\n' +
|
||||
'RO {roumain}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
"} n'est pas autorisé.",
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName} értéket.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Osztrák}\n' +
|
||||
'BE {Belga}\n' +
|
||||
'CZ {Cseh}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Holland}\n' +
|
||||
'PL {Lengyel}\n' +
|
||||
'RO {Román}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} nem engedélyezett.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'}.',
|
||||
IsNotCountryIBAN:
|
||||
'{fieldName} {params, select,\n' +
|
||||
'{fieldName} {userSuppliedCountryCode, select,\n' +
|
||||
'AT {Austriaco}\n' +
|
||||
'BE {Belga}\n' +
|
||||
'CZ {Ceco}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Olandese}\n' +
|
||||
'PL {Polacco}\n' +
|
||||
'RO {Rumeno}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} non è permesso.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName} in.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Oostenrijkse}\n' +
|
||||
'BE {Belgische}\n' +
|
||||
'CZ {Tsjechische}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Nederlandse}\n' +
|
||||
'PL {Poolse}\n' +
|
||||
'RO {Roemeense}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} is niet toegestaan.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Austriacki}\n' +
|
||||
'BE {Belgijski}\n' +
|
||||
'CZ {Czeski}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Holenderski}\n' +
|
||||
'PL {Polski}\n' +
|
||||
'RO {Rumuński}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} nie jest dozwolone.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} valid(ă).',
|
||||
IsNotCountryIBAN:
|
||||
'{fieldName} {params, select,\n' +
|
||||
'{fieldName} {userSuppliedCountryCode, select,\n' +
|
||||
'AT {austriac}\n' +
|
||||
'BE {belgian}\n' +
|
||||
'CZ {ceh}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {olandez}\n' +
|
||||
'PL {polonez}\n' +
|
||||
'RO {românesc}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} nu este permis.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Австрийский}\n' +
|
||||
'BE {Бельгийский}\n' +
|
||||
'CZ {Чешский}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Нидерландский}\n' +
|
||||
'PL {Польский}\n' +
|
||||
'RO {Румынский}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} не допускается.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} kód {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Rakúsky}\n' +
|
||||
'BE {Belgický}\n' +
|
||||
'CZ {Český}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Holandský}\n' +
|
||||
'PL {Poľský}\n' +
|
||||
'RO {Rumunský}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} nie je povolené.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'other {{params}}\n' +
|
||||
'} {fieldName}.',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {Австрійський}\n' +
|
||||
'BE {Бельгійський}\n' +
|
||||
'CZ {Чеський}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {Голландський}\n' +
|
||||
'PL {Польський}\n' +
|
||||
'RO {Румунська}\n' +
|
||||
'other {{params}}\n' +
|
||||
'other {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} не дозволено.',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default {
|
|||
'另一个 {{params}}\n' +
|
||||
'} {fieldName}。',
|
||||
IsNotCountryIBAN:
|
||||
'{params, select,\n' +
|
||||
'{userSuppliedCountryCode, select,\n' +
|
||||
'AT {奥}\n' +
|
||||
'BE {比利时的}\n' +
|
||||
'CZ {捷克}\n' +
|
||||
|
|
@ -29,7 +29,7 @@ export default {
|
|||
'NL {荷兰人}\n' +
|
||||
'PL {抛光}\n' +
|
||||
'RO {罗马尼亚}\n' +
|
||||
'另一个 {{params}}\n' +
|
||||
'另一个 {{userSuppliedCountryCode}}\n' +
|
||||
'} {fieldName} 不允許。',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue