小编Boj*_*vic的帖子

如何为 React Material-UI TextField 和 Select 应用表单验证?

我正在尝试在执行 handleNext() 之前向 TextField 和 Select 添加验证。这是代码(2 个组件):

class Quote extends React.Component {
state = {
    activeStep: 0,
    zipCode: '',
    destination: '',
    sedanPrice: '',
    suvPrice: '',
    labelWidth: 0,
};

getStepContent = (step) => {
    switch (step) {
        case 0:
            return (
                <div>
                    <QuoteForm
                        {...this.state}
                        {...this.state.value}
                        handleChange={this.handleChange}
                    />
                </div>
            )
        case 1:
            return (
                <div>
                    <QuotePrice 
                        {...this.state}
                        {...this.state.value}
                    />
                </div>
            )
        default:
            throw new Error('Unknown step');
    }
}

handleNext = () => {
    this.setState(prevState => ({
        activeStep: prevState.activeStep + 1,
    })); …
Run Code Online (Sandbox Code Playgroud)

validation reactjs material-ui react-material-ui-form-validator

7
推荐指数
1
解决办法
3万
查看次数