Skip to content

Commit

Permalink
Support function for locator-based validators (#30528)
Browse files Browse the repository at this point in the history
Allow a function to be passed as the reference to the ref helper and the
requiredIf, requiredUnless and sameAs validators.
  • Loading branch information
aharonp authored and PranavSenthilnathan committed Nov 17, 2018
1 parent 1d99009 commit d202969
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions types/vuelidate/lib/validators.d.ts
Expand Up @@ -23,7 +23,7 @@ export type CustomRule = (value: any, parentVm?: Vue) => boolean
export interface Helpers {
withParams(params: Params, rule: CustomRule): ValidationRule
req(value: any): ValidationRule
ref(reference: string, vm: any, parentVm?: Vue): any
ref(reference: string | ((vm: any, parentVm?: Vue) => any), vm: any, parentVm?: Vue): any
len(value: any): number
regex(type: string, expr: RegExp): ValidationRule
}
Expand All @@ -32,8 +32,8 @@ export const helpers: Helpers

// pre-defined rules
export function required(): ValidationRule
export function requiredIf(field: string): ValidationRule
export function requiredUnless(field: string): ValidationRule
export function requiredIf(field: string | ((vm: any, parentVm?: Vue) => any)): ValidationRule
export function requiredUnless(field: string | ((vm: any, parentVm?: Vue) => any)): ValidationRule
export function minLength(length: number): ValidationRule
export function maxLength(length: number): ValidationRule
export function minValue(min: number): ValidationRule
Expand All @@ -45,7 +45,7 @@ export function numeric(): ValidationRule
export function email(): ValidationRule
export function ipAddress(): ValidationRule
export function macAddress(): ValidationRule
export function sameAs(field: string): ValidationRule
export function sameAs(field: string | ((vm: any, parentVm?: Vue) => any)): ValidationRule
export function url(): ValidationRule
export function or(...validators: ValidationRule[]): ValidationRule
export function and(...validators: ValidationRule[]): ValidationRule
3 changes: 2 additions & 1 deletion types/vuelidate/vuelidate-tests.ts
Expand Up @@ -45,7 +45,8 @@ const mustHaveLength = (minLen: number) => helpers.withParams(
},
repeatPassword: {
sameAsPassword: sameAs('password'),
mustBeSame: mustBeSame('password')
mustBeSame: mustBeSame('password'),
sameAsPassword2: sameAs(vm => vm.password)
},
form: {
nestedA: {
Expand Down

0 comments on commit d202969

Please sign in to comment.