mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
Add rank selection and condition handling to certificate designer and requirements
This commit is contained in:
@@ -558,14 +558,25 @@ export function validateSections(
|
||||
}
|
||||
|
||||
/** Evaluates a config condition against the current form answers. */
|
||||
interface ConditionLike {
|
||||
field?: string;
|
||||
equals?: unknown;
|
||||
notEquals?: unknown;
|
||||
in?: (string | number)[];
|
||||
isSet?: boolean;
|
||||
/** Holds when ANY listed sub-condition holds — see FieldCondition.anyOf. */
|
||||
anyOf?: ConditionLike[];
|
||||
}
|
||||
|
||||
export function conditionHolds(
|
||||
condition:
|
||||
| { field: string; equals?: unknown; notEquals?: unknown; in?: (string | number)[]; isSet?: boolean }
|
||||
| undefined
|
||||
| null,
|
||||
condition: ConditionLike | undefined | null,
|
||||
formData: Record<string, Record<string, unknown>>,
|
||||
): boolean {
|
||||
if (!condition?.field) return true;
|
||||
if (!condition) return true;
|
||||
if (condition.anyOf) {
|
||||
return condition.anyOf.some((sub) => conditionHolds(sub, formData));
|
||||
}
|
||||
if (!condition.field) return true;
|
||||
const value = condition.field
|
||||
.split('.')
|
||||
.reduce<unknown>(
|
||||
|
||||
@@ -67,11 +67,18 @@ export type FormFieldType =
|
||||
| "TIN";
|
||||
|
||||
export interface FieldCondition {
|
||||
field: string;
|
||||
/** Omitted when `anyOf` is used instead — see below. */
|
||||
field?: string;
|
||||
equals?: string | number | boolean;
|
||||
notEquals?: string | number | boolean;
|
||||
in?: (string | number)[];
|
||||
isSet?: boolean;
|
||||
/**
|
||||
* Holds when ANY listed condition holds — for a value that can live on one
|
||||
* of several mutually-exclusive fields (e.g. a rank split by department).
|
||||
* `field`/`equals`/etc are ignored when this is present.
|
||||
*/
|
||||
anyOf?: FieldCondition[];
|
||||
}
|
||||
|
||||
export interface FormFieldConfig {
|
||||
|
||||
Reference in New Issue
Block a user