mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-27 03:16:33 +07:00
add test group validation
This commit is contained in:
parent
34f81fbe1a
commit
ec5ebba12e
@ -73,8 +73,32 @@ export const testCalSchema = z
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const testGroupSchema = z.object({
|
export const testGroupSchema = z
|
||||||
Members: z.string().optional()
|
.object({
|
||||||
|
Members: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
id: z.number(),
|
||||||
|
value: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional()
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (!data.Members) return;
|
||||||
|
|
||||||
|
const values = data.Members.map(m => m.value).filter(Boolean);
|
||||||
|
const duplicates = values.filter((v, i) => values.indexOf(v) !== i);
|
||||||
|
|
||||||
|
if (duplicates.length) {
|
||||||
|
const uniqueDuplicates = [...new Set(duplicates)];
|
||||||
|
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: `Duplicate member : ${uniqueDuplicates.join(", ")}`,
|
||||||
|
path: ["Members"]
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const refNumSchema = z
|
export const refNumSchema = z
|
||||||
@ -284,7 +308,7 @@ export const testCalDefaultErrors = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const testGroupDefaultErrors = {
|
export const testGroupDefaultErrors = {
|
||||||
Members: 'fdsa',
|
Members: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const refNumDefaultErrors = {
|
export const refNumDefaultErrors = {
|
||||||
@ -618,7 +642,7 @@ export const testGroupFormFields = [
|
|||||||
type: 'row',
|
type: 'row',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
key: 'Member',
|
key: 'Members',
|
||||||
label: 'Member Test',
|
label: 'Member Test',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'members',
|
type: 'members',
|
||||||
|
|||||||
@ -17,10 +17,10 @@
|
|||||||
// function removeMember(id) {
|
// function removeMember(id) {
|
||||||
// members = members.filter((m) => m.id !== id);
|
// members = members.filter((m) => m.id !== id);
|
||||||
// }
|
// }
|
||||||
// $inspect(props.groupFormState.form)
|
// $inspect(props.groupFormState.form.Members)
|
||||||
function removeMember(id) {
|
function removeMember(id) {
|
||||||
props.groupFormState.form.Members =
|
props.groupFormState.form.Members = props.groupFormState.form.Members.filter((m) => m.id !== id);
|
||||||
props.groupFormState.form.Members.filter((m) => m.id !== id);
|
props.groupFormState.validateField?.("Members", props.groupFormState.form.Members, false);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -654,6 +654,12 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onValueChange={() => {
|
||||||
|
console.log(key);
|
||||||
|
if (validateOn?.includes('input')) {
|
||||||
|
formState.validateField?.(key, formState.form[key], false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Select.Trigger class="w-full">
|
<Select.Trigger class="w-full">
|
||||||
{selectedLabel}
|
{selectedLabel}
|
||||||
@ -704,7 +710,7 @@
|
|||||||
placeholder="Custom field type: {type}"
|
placeholder="Custom field type: {type}"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<div class={`absolute min-h-[1rem] w-full ${key === 'FormulaCode' ? 'top-10' : 'top-10'}`}>
|
<div class={`absolute min-h-[1rem] w-full ${key === 'Members' ? 'right-0 -top-5 text-right' : 'top-10'}`}>
|
||||||
{#if key !== 'FormulaCode' && (formState.errors[key] || formState.errors[txtKey])}
|
{#if key !== 'FormulaCode' && (formState.errors[key] || formState.errors[txtKey])}
|
||||||
{@const errorMessage = formState.errors[key] ?? formState.errors[txtKey]}
|
{@const errorMessage = formState.errors[key] ?? formState.errors[txtKey]}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user