Skip to content

Commit

Permalink
fix: remove default Select and Radio options
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-belcher committed Nov 15, 2023
1 parent bf42c39 commit ce5e238
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/services/ui/src/components/RHF/utils/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,27 @@ export const slotInitializer = (ACC: GL, SLOT: T.RHFSlotProps): GL => {
return { ...ACC1, ...slotInitializer(ACC1, SLOT) };
};

if (SLOT.rhf === "Input") ACC[SLOT.name] = "";
if (SLOT.rhf === "Textarea") ACC[SLOT.name] = "";
if (SLOT.rhf === "Switch") ACC[SLOT.name] = false;
if (SLOT.rhf === "Radio") {
if (SLOT.props?.options) {
SLOT.props.options.forEach(optionReducer);
const [first] = SLOT.props.options;
ACC[SLOT.name] = first.value;
}
}

if (SLOT.rhf === "Select") {
if (SLOT.props?.options) {
SLOT.props.options.forEach(optionReducer);
const [first] = SLOT.props.options;
ACC[SLOT.name] = first.value;
}
}

if (SLOT.rhf === "Checkbox") {
if (SLOT.props?.options) {
SLOT.props.options.forEach(optionReducer);
switch (SLOT.rhf) {
case "Switch":
ACC[SLOT.name] = false;
break;
case "Radio":
case "Checkbox":
SLOT.props?.options.forEach(optionReducer);
ACC[SLOT.name] = [];
}
break;
case "FieldArray":
case "FieldGroup":
ACC[SLOT.name] = [SLOT.fields?.reduce(fieldInitializer, {})];
break;
case "Input":
case "Select":
case "Textarea":
default:
ACC[SLOT.name] = "";
break;
}

if (SLOT.rhf === "FieldArray")
ACC[SLOT.name] = [SLOT.fields?.reduce(fieldInitializer, {})];
if (SLOT.rhf === "FieldGroup")
ACC[SLOT.name] = [SLOT.fields?.reduce(fieldInitializer, {})];

return ACC;
};

Expand Down

0 comments on commit ce5e238

Please sign in to comment.