Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step Form - First Step with isEnabled=false #232

Open
ntatoud opened this issue Mar 9, 2025 · 0 comments
Open

Step Form - First Step with isEnabled=false #232

ntatoud opened this issue Mar 9, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ntatoud
Copy link

ntatoud commented Mar 9, 2025

Describe the bug

When loading a multi step form where the 1st FormizStep is disabled, no step is rendered.

Codesandbox

See codesandbox

To Reproduce

  1. In a multi step form, set isEnabled to false for the first FormizStep.
  2. Load the page

Expected behavior

This step should not be rendered, but the following one in order should

Screenshots

Image

Additional context

The issue comes from the registerStep action in the store:

 registerStep: (stepName, { label, order = 0, isEnabled = true } = {}) =>
        set((state) => {
          return {
            steps: [
              ...state.steps,
              {
                name: stepName,
                label,
                isSubmitted: false,
                isVisited: false,
                order,
                isEnabled,
              },
            ].sort((stepA, stepB) => stepA.order - stepB.order),
            form: {
              ...state.form,
              currentStepName: state.form.currentStepName ?? stepName, // <- HERE
            },
          };
        }),

If the step is not enabled, it will still register it as the form.currentStepName and mess with rendering of the steps.
I think it could also be nice to have some safety check if 'initialStepName' is a disabled step.

On a similar note, I think that the computation for the value isFirstStep and isLastStep should be on enabled steps and not all steps:

// formInterfaceSelector
...isFormStateSubscribed(
      "isFirstStep",
      state.steps[0]?.name === currentStep?.name,
      stateSubscription
    ),
    ...isFormStateSubscribed(
      "isLastStep",
      state.steps[state.steps.length - 1]?.name === currentStep?.name,
      stateSubscription
    ),
  };
@ntatoud ntatoud added the bug Something isn't working label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant