mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
feat: add useArrayRule to generate rules for each array elem
This commit is contained in:
parent
85b4980bee
commit
a22ee09344
1 changed files with 14 additions and 2 deletions
|
@ -5,8 +5,8 @@ import type {
|
|||
ValidationRuleCollection,
|
||||
} from '@vuelidate/core'
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import type { InjectionKey, MaybeRefOrGetter, Ref } from 'vue'
|
||||
import { inject, provide, reactive, toValue } from 'vue'
|
||||
import type { ComputedRef, InjectionKey, MaybeRefOrGetter, Ref } from 'vue'
|
||||
import { computed, inject, provide, reactive, toValue } from 'vue'
|
||||
import { computedWithControl } from '@vueuse/core'
|
||||
|
||||
import { APIBadRequestError, type APIError } from '@/api/errors'
|
||||
|
@ -128,3 +128,15 @@ export function deepSetErrors(
|
|||
serverErrors[k] = value
|
||||
}
|
||||
}
|
||||
|
||||
export function useArrayRule<V extends any[], T extends ValidationArgs>(
|
||||
values: MaybeRefOrGetter<V>,
|
||||
rules: T,
|
||||
): ComputedRef<ValidationArgs<T>> {
|
||||
return computed(() => {
|
||||
return toValue(values).reduce((total: Obj<T>, v: V[number], index) => {
|
||||
total[index] = rules
|
||||
return total
|
||||
}, {})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue