handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
34 lines (32 loc) • 1.15 kB
JavaScript
import { isValidTime } from "../../helpers/dateTime.mjs";
import { isEmpty } from "../../helpers/mixed.mjs";
export const VALIDATOR_TYPE = 'intl-time';
export const SOURCE_DATA_WARNING_MESSAGE = 'Source data warning ([itemsCount]). ' + 'Invalid value for "intl-time" cell type.\n\n' + '[affectedCells]\n\n' + 'Expected a value compatible with the 24-hour time format ("HH:mm", "HH:mm:ss" or "HH:mm:ss.SSS").';
/**
* Source data validator.
*
* @param {*} value Value of the source data of the cell.
* @param {CellMeta} cellMeta Cell meta object.
* @returns {boolean} True if valid, false otherwise.
*/
export function sourceDataValidator(value, cellMeta) {
if (cellMeta.allowEmpty && isEmpty(value)) {
return true;
}
return isValidTime(value);
}
/**
* The IntlTime cell validator.
*
* @private
* @param {*} value Value of edited cell.
* @param {Function} callback Callback called with validation result.
*/
export function intlTimeValidator(value, callback) {
if (this.allowEmpty && isEmpty(value)) {
callback(true);
return;
}
callback(isValidTime(value));
}
intlTimeValidator.VALIDATOR_TYPE = VALIDATOR_TYPE;