From b03cda336281d0fe3762c05d3e8787872a911699 Mon Sep 17 00:00:00 2001 From: Charles Demers Date: Fri, 11 Feb 2022 10:21:07 -0500 Subject: [PATCH 1/2] Fix "confirmation" validation by passing `model` and `attribute` arguments along to `validate` --- addon/index.js | 4 ++-- index.d.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addon/index.js b/addon/index.js index 8818f03..af09260 100644 --- a/addon/index.js +++ b/addon/index.js @@ -92,9 +92,9 @@ export default function validationState(VALIDATOR_FNS) { * @param {object} context - the options hash passed along to ember-validators * @returns {function<*, MessageBuilder>: [isValid: boolean, message?: string]} */ -export function validate(eventName, context) { +export function validate(eventName, context, model, attribute) { return function (value, messageSvc) { - const validOrContext = _validate(eventName, value, context); + const validOrContext = _validate(eventName, value, context, model, attribute); if (typeof validOrContext === 'boolean') { return [true]; diff --git a/index.d.ts b/index.d.ts index a6abed9..d8d563f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,21 +1,21 @@ type Validators = Record; -type AttributeValidation = { +interface AttributeValidation { messages: string[]; isValid: boolean; -}; +} type AttrsType = { [P in keyof T]: AttributeValidation; }; -export type ValidationState = { +export interface ValidationState { isValid: boolean; attrs: AttrsType; -}; +} -export function validate(any, any): any; +export function validate(validatorName: any, context: any, model?: any, attribute?: string): any; export default function validationState( validators: Validators | ((ctx: any) => Validators) -): PropertyDescriptor>; +): (target: T, key: keyof T) => void; From 7340c1688ad143b08619973421eb9988a7df543b Mon Sep 17 00:00:00 2001 From: Charles Demers Date: Fri, 11 Feb 2022 10:31:24 -0500 Subject: [PATCH 2/2] Fix formatting --- addon/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addon/index.js b/addon/index.js index af09260..9293d04 100644 --- a/addon/index.js +++ b/addon/index.js @@ -94,7 +94,13 @@ export default function validationState(VALIDATOR_FNS) { */ export function validate(eventName, context, model, attribute) { return function (value, messageSvc) { - const validOrContext = _validate(eventName, value, context, model, attribute); + const validOrContext = _validate( + eventName, + value, + context, + model, + attribute + ); if (typeof validOrContext === 'boolean') { return [true];