Skip to content

Commit

Permalink
Merge pull request #702 from near/configurator-initial-values
Browse files Browse the repository at this point in the history
fix: force initial string values in form configurator
  • Loading branch information
charleslavon authored Mar 14, 2024
2 parents 776305f + fff6871 commit 6439b97
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Entities/Template/EntityCreate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ const inputsValidator = (formValues) =>
return !required || typeof formValues[key] === "string";
});

const actionType = data ? (data.accountId == context.accountId ? "Edit" : "Fork") : "Create";
const actionType = data ? (data.accountId === context.accountId ? "Edit" : "Fork") : "Create";

const initialValues = (schema, data) => {
const initial = data ?? {};
Object.keys(schema).forEach((key) => {
const fieldProps = schema[key];
if (!data[key] && fieldProps.displayType !== "hidden" && fieldProps.type === "string") {
initial[key] = "";
}
});
return initial;
};

return (
<Widget
Expand All @@ -47,7 +58,7 @@ return (
submitLabel: data ? "Save" : "Launch",
onCancel: onCancel,
cancelLabel: cancelLabel,
externalState: data,
externalState: initialValues(schema, data),
}}
/>
);

0 comments on commit 6439b97

Please sign in to comment.