Merge pull request #262 from vicdata4/fix/input-amount-locale
Fix: pass string instead of object in input-amount parser
This commit is contained in:
commit
1c697b10c6
2 changed files with 15 additions and 1 deletions
|
|
@ -60,7 +60,8 @@ function getParseMode(value) {
|
|||
* @param {object} options Locale Options
|
||||
*/
|
||||
function parseWithLocale(value, options) {
|
||||
const separator = getDecimalSeparator(options);
|
||||
const locale = options && options.locale ? options.locale : null;
|
||||
const separator = getDecimalSeparator(locale);
|
||||
const regexNumberAndLocaleSeparator = new RegExp(`[0-9${separator}-]`, 'g');
|
||||
let numberAndLocaleSeparator = value.match(regexNumberAndLocaleSeparator).join('');
|
||||
if (separator === ',') {
|
||||
|
|
|
|||
|
|
@ -145,4 +145,17 @@ describe('parseAmount()', () => {
|
|||
it('returns undefined when value is empty string', () => {
|
||||
expect(parseAmount('')).to.equal(undefined);
|
||||
});
|
||||
|
||||
it('parseAmount with locale set and length is more than four', () => {
|
||||
expect(
|
||||
parseAmount('6,000', {
|
||||
locale: 'gb-GB',
|
||||
}),
|
||||
).to.equal(6000);
|
||||
expect(
|
||||
parseAmount('6.000', {
|
||||
locale: 'es-ES',
|
||||
}),
|
||||
).to.equal(6000);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue