@@ -2,30 +2,37 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import Button from '../button' ;
44import { Icon , Wizard } from 'patternfly-react' ;
5- import { useFieldApi } from '@data-driven-forms/react-form-renderer' ;
5+ import { useFieldApi , useFormApi } from '@data-driven-forms/react-form-renderer' ;
66
77import './button.scss' ;
88
9- const SimpleNext = ( { next, valid, handleNext, submit, buttonLabels } ) => (
10- < Button className = "margin-left-3" bsStyle = "primary" type = "button" onClick = { ( ) => ( valid ? handleNext ( next ) : submit ( ) ) } >
11- { buttonLabels . next }
12- < Icon type = "fa" name = "angle-right" />
13- </ Button >
14- ) ;
9+ const SimpleNext = ( { next, handleNext, submit, buttonLabels, disabled } ) => {
10+ const { valid } = useFormApi ( ) ;
11+
12+ return (
13+ < Button className = "margin-left-3" bsStyle = "primary" type = "button" onClick = { ( ) => ( valid ? handleNext ( next ) : submit ( ) ) } disabled = { disabled } >
14+ { buttonLabels . next }
15+ < Icon type = "fa" name = "angle-right" />
16+ </ Button >
17+ ) ;
18+ } ;
1519
1620SimpleNext . propTypes = {
1721 next : PropTypes . string ,
18- valid : PropTypes . bool ,
1922 handleNext : PropTypes . func . isRequired ,
2023 submit : PropTypes . func . isRequired ,
21- buttonLabels : PropTypes . object . isRequired
24+ buttonLabels : PropTypes . object . isRequired ,
25+ disabled : PropTypes . bool
2226} ;
2327
2428const ConditionalNext = ( { nextStep, ...rest } ) => {
2529 const {
2630 input : { value }
2731 } = useFieldApi ( { name : nextStep . when , subscription : { value : true } } ) ;
28- return < SimpleNext next = { nextStep . stepMapper [ value ] } { ...rest } /> ;
32+
33+ const next = nextStep . stepMapper [ value ] ;
34+
35+ return < SimpleNext next = { next } { ...rest } disabled = { ! next } /> ;
2936} ;
3037
3138ConditionalNext . propTypes = {
0 commit comments