Skip to content

Commit d6abc18

Browse files
authored
feat(create-headless-form) - add the posibility to add required and allOf (#707)
* feat(create-headless-form) - add the posibility to add required and allOff * fix types
1 parent 03694df commit d6abc18

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/common/createHeadlessForm.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ export const createHeadlessForm = (
2828
options?: { jsfModify?: JSFModify },
2929
): CreateHeadlessFormResult => {
3030
if (options && options.jsfModify) {
31-
const { schema } = modify(jsfSchema, options.jsfModify);
31+
const { required, allOf, ...modifyConfig } = options.jsfModify;
32+
const { schema } = modify(jsfSchema, modifyConfig);
3233
jsfSchema = schema;
34+
35+
if (required) {
36+
jsfSchema.required = [...schema.required, ...required];
37+
}
38+
39+
if (allOf) {
40+
jsfSchema.allOf = [...(schema.allOf || []), ...allOf];
41+
}
3342
}
3443

3544
let moneyFieldsData: Record<string, number | null> = {};

src/flows/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,16 @@ export type JSONSchemaFormType =
7474
// Benefits forms
7575
| 'benefit_renewal_request';
7676

77-
export type JSFModify = ModifyConfig;
77+
export type JSFModify = ModifyConfig & {
78+
/**
79+
* allows to specify additional required fields for the form.
80+
*/
81+
required?: string[];
82+
/**
83+
* allows to specify additional allOf rules for the form.
84+
*/
85+
allOf?: unknown[];
86+
};
7887

7988
export type FlowOptions = {
8089
jsfModify?: JSFModify;

0 commit comments

Comments
 (0)