Skip to content

Commit

Permalink
FIX error in collapse...sorry ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Feb 16, 2022
1 parent 1037b32 commit 23a4412
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const Form = React.forwardRef(({ schema, flow, value, inputWrapper, onSub
{formFlow.map((entry, idx) => {
const step = schema[entry]

if (!step) {
if (!step && typeof entry === 'string') {
console.error(`no step found for the entry "${entry}" in the given schema. Your form might not work properly. Please fix it`)
return null;
}
Expand Down Expand Up @@ -283,17 +283,6 @@ const Footer = (props) => {
const Step = ({ entry, realEntry, step, error, errors, register, schema, control, trigger, getValues, setValue, watch, inputWrapper, httpClient, defaultValue, index }) => {
const classes = useCustomStyle();

const registeredInput = register(entry);
const inputProps = {
...registeredInput,
onChange: (e) => {
registeredInput.onChange(e);
option(step.onChange)
.map(onChange => onChange({ rawValues: getValues(), value: e.target.value, setValue }))
}
}


if (entry && typeof entry === 'object') {
const errored = entry.flow.some(step => !!errors[step])
return (
Expand All @@ -304,6 +293,11 @@ const Step = ({ entry, realEntry, step, error, errors, register, schema, control
return object && object[key];
}, errors);

if (!stp && typeof en === 'string') {
console.error(`no step found for the entry "${en}" in the given schema. Your form might not work properly. Please fix it`)
return null;
}

const visibleStep = option(stp)
.map(s => s.visible)
.map(visible => {
Expand Down Expand Up @@ -335,6 +329,16 @@ const Step = ({ entry, realEntry, step, error, errors, register, schema, control
)
}

const registeredInput = register(entry);
const inputProps = {
...registeredInput,
onChange: (e) => {
registeredInput.onChange(e);
option(step.onChange)
.map(onChange => onChange({ rawValues: getValues(), value: e.target.value, setValue }))
}
}

const disabled = () => {
if (typeof step.disabled === 'function') {
return step.disabled({ rawValues: getValues(), value: getValues(entry) });
Expand Down Expand Up @@ -786,7 +790,7 @@ const NestedForm = ({ schema, flow, parent, inputWrapper, maybeCustomHttpClient,
}
}, [prevSchema, schemaAndFlow.schema])

const test = schemaAndFlow.flow.reduce((acc, entry) => {
const computedSandF = schemaAndFlow.flow.reduce((acc, entry) => {
const step = schemaAndFlow.schema[entry]

const visibleStep = option(step)
Expand All @@ -807,13 +811,19 @@ const NestedForm = ({ schema, flow, parent, inputWrapper, maybeCustomHttpClient,
return [...acc, { step, visibleStep, entry }]
}, [])

const bordered = test.filter(x => x.visibleStep).length <= 1 && step.label === null;
const bordered = computedSandF.filter(x => x.visibleStep).length <= 1 && step.label === null;
return (
<div className={classNames({ [classes.nestedform__border]: bordered })}>
{!!step.collapsable && schemaAndFlow.flow.length > 1 && collapsed && <ArrowDown size={30} className={classes.cursor_pointer} style={{ position: 'absolute', top: '5px', left: '-16px' }} stroke-width="3" onClick={() => setCollapsed(!collapsed)} />}
{!!step.collapsable && schemaAndFlow.flow.length > 1 && !collapsed && <ArrowUp size={30} className={classes.cursor_pointer} style={{ position: 'absolute', top: '5px', left: '-16px' }} strok-width="3" onClick={() => setCollapsed(!collapsed)} />}

{test.map(({ step, visibleStep, entry }, idx) => {
{computedSandF.map(({ step, visibleStep, entry }, idx) => {

if (!step && typeof entry === 'string') {
console.error(`no step found for the entry "${entry}" in the given schema. Your form might not work properly. Please fix it`)
return null;
}

const realError = error && error[entry]
const oneVisibleSetup = Object.values(schemaAndFlow.schema).some(v => !!v.visibleOnCollapse)
const isCollapsed = collapsed && (oneVisibleSetup ? !step.visibleOnCollapse : idx > 0)
Expand Down

0 comments on commit 23a4412

Please sign in to comment.