UNPKG

@lion/form-core

Version:

Form-core contains all essential building blocks for creating form fields and fieldsets

34 lines (29 loc) 1.02 kB
import { ResultValidator } from '../ResultValidator.js'; /** * @typedef {import('../Validator').Validator} Validator */ export class DefaultSuccess extends ResultValidator { /** * @param {...any} args */ constructor(...args) { super(...args); this.type = 'success'; } /** * * @param {Object} context * @param {Validator[]} context.regularValidationResult * @param {Validator[]} context.prevValidationResult * @param {Validator[]} context.prevShownValidationResult * @returns {boolean} */ // eslint-disable-next-line class-methods-use-this executeOnResults({ regularValidationResult, prevShownValidationResult }) { const errorOrWarning = /** @param {Validator} v */ v => v.type === 'error' || v.type === 'warning'; const hasErrorOrWarning = !!regularValidationResult.filter(errorOrWarning).length; const hasShownErrorOrWarning = !!prevShownValidationResult.filter(errorOrWarning).length; return !hasErrorOrWarning && hasShownErrorOrWarning; } }