lion/packages/ui/components/input-amount-dropdown/src/validators.js
Robin Van Roy 57800c4501
chore: adds lion-input-amount-dropdown (#2505)
Co-authored-by: gerjanvangeest <Gerjan.van.Geest@ing.com>
2025-08-13 14:40:57 +02:00

22 lines
796 B
JavaScript

import { IsNumber, Validator } from '@lion/ui/form-core.js';
import { currencyUtil } from './currencyUtil.js';
/**
* @typedef {import('../../form-core/types/validate/validate.js').FeedbackMessageData} FeedbackMessageData
*/
export class CurrencyAndAmount extends Validator {
static validatorName = 'CurrencyAndAmount';
/**
* @param {import('../types/index.js').AmountDropdownModelValue} modelValue amount and currency symbol
*/
// eslint-disable-next-line class-methods-use-this
execute(modelValue) {
// @ts-expect-error - cannot cast string to CurrencyCode outside a TS file
const validCurrencyCode = currencyUtil.allCurrencies.has(modelValue?.currency);
const isNumber = new IsNumber().execute(modelValue.amount);
return validCurrencyCode && isNumber;
}
}