MCPcopy Create free account
hub / github.com/formkit/formkit / multiStepPlugin

Function multiStepPlugin

packages/addons/src/plugins/multiStep/multiStepPlugin.ts:536–774  ·  view source on GitHub ↗
(node: FormKitNode)

Source from the content-addressed store, hash-verified

534 let isFirstStep = true
535
536 const multiStepPlugin = (node: FormKitNode) => {
537 if (node.props.type === 'multi-step') {
538 if (!node.context) return
539
540 isFirstStep = true // reset variable, next step will be first step in multistep
541 node.addProps(['steps', 'tabs', 'activeStep', '_pendingStepTarget'])
542
543 node.context.fns.preRenderSteps = createPreRenderStepsFunction(node)
544 node.context.fns.getStepCount = () => {
545 if (!node.context) return
546 return node.context.stepCount
547 }
548 node.context.fns.getSteps = () => {
549 if (!node.context) return
550 return node.context.steps
551 }
552
553 node.props.allowIncomplete =
554 typeof node.props.allowIncomplete === 'boolean'
555 ? node.props.allowIncomplete
556 : typeof options?.allowIncomplete === 'boolean'
557 ? options?.allowIncomplete
558 : true
559 node.props.hideProgressLabels =
560 typeof node.props.hideProgressLabels === 'boolean'
561 ? node.props.hideProgressLabels
562 : options?.hideProgressLabels || false
563 node.props.tabStyle = node.props.tabStyle || options?.tabStyle || 'tab'
564
565 node.context.handlers.triggerStepValidations = triggerStepValidations
566 node.context.handlers.showStepErrors = showStepErrors
567
568 node.on('created', () => {
569 if (!node.context) return
570
571 node.extend('next', {
572 get: (node) => () => {
573 incrementStep(
574 1,
575 node?.props?.steps.find(
576 (step: Record<string, any>) => step.isActiveStep
577 )
578 )
579 },
580 set: false,
581 })
582 node.extend('previous', {
583 get: (node) => () => {
584 incrementStep(
585 -1,
586 node?.props?.steps.find(
587 (step: Record<string, any>) => step.isActiveStep
588 )
589 )
590 },
591 set: false,
592 })
593 node.extend('goTo', {

Callers

nothing calls this directly

Calls 13

whenAvailableFunction · 0.90
isPlaceholderFunction · 0.90
incrementStepFunction · 0.85
goToStepFunction · 0.85
initEventsFunction · 0.85
orderStepsFunction · 0.85
setNodePositionPropsFunction · 0.85
setStepNameFunction · 0.85
getTargetStepFunction · 0.85
setActiveStepFunction · 0.85
updateTotalErrorCountFunction · 0.85

Tested by

no test coverage detected