Skip to content
Snippets Groups Projects
Commit b96548931ff8 authored by Frank Bessou's avatar Frank Bessou :spider_web:
Browse files

feat: Make formHelper.getInputProps handle default values

parent 79e4ae8409ae
No related branches found
No related tags found
1 merge request!15Topic/default/default values
Pipeline #39771 passed
......@@ -7,6 +7,7 @@
User: {
login: { type: "String", required: true } as const,
address: { type: "String" } as const,
active: { type: "Boolean", default: true } as const,
},
},
relationsDefinitions: [],
......@@ -29,5 +30,15 @@
const props = formHelpers.User.getInputProps("login");
expect(isRequired(props.validate)).toBe(true);
});
it("returns an 'initialValue' property when the attribute has a default value", () => {
const props = formHelpers.User.getInputProps("active");
expect(props.initialValue).toBe(true);
});
it("returns no 'initialValue' property when the attribute has no default value", () => {
const props = formHelpers.User.getInputProps("active");
expect(props.initialValue).toBe(true);
});
});
});
......@@ -17,7 +17,7 @@
entityType: SchemaEntityTypes<S>,
attributeName: EntityAttributeNames<EntityType>
) {
const entitySchema = schema.entities[entityType];
const attributeSchema = schema.entities[entityType][attributeName];
const props: InputProps = {
source: attributeName,
};
......@@ -21,6 +21,6 @@
const props: InputProps = {
source: attributeName,
};
if (entitySchema[attributeName].required) {
if (attributeSchema.required) {
props.validate = [required()];
}
......@@ -25,5 +25,8 @@
props.validate = [required()];
}
if (attributeSchema.default !== undefined) {
props.initialValue = attributeSchema.default;
}
return props;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment