reactjs 我怎样才能在选择提交按钮后才将来自andd datepicker的响应发送到后端?

mxg2im7a  于 2023-01-30  发布在  React
关注(0)|答案(1)|浏览(88)

我从andd datepicker得到了一个回复,我可以很好地将回复发送到后端,但这里的问题是,一旦选择了日期,回复就会发送到后端。我需要在此之前提交,只有在单击提交按钮后,我才想将请求发送到后端。
我如何使请求发送到后端后,才通过点击提交按钮与ReactJS?

<div className='col-12 mt-4'>
    <div className='row'>
        <div className='col-8'>
            <div className="profile-card-title">Add a session{' '}:{''} <span style={{ fontWeight: '400' }}>
                <DatePicker
                    onChange={this.onChangeextra}
                    disabledDate={this.disabledDate}
                    />
                    </span>
            </div>
        </div>
        <div className='col-4'>
        <Button className="Add-now-btn mr-3"
        onClick={}> ---> i want the onChangeextra function to happen only after i slect the submit button.
        Submit
        </Button>
        </div>
    </div>
</div>

onchange调用onReschdulechange函数

onChangeextra= (
        value,
        dateString
    ) => {
        let type = "reschdule class"
        console.log('Selected Time: ', value);
        console.log('Formatted Selected Time: ', dateString);
        this.onReschduleClasses(value, type); ---> Request is sent to the backend.
    };
niwlg2el

niwlg2el1#

我在类函数中得到了这个finally add状态的答案

state = {
selectedDate:null
}

然后使用此状态存储日期值

<div className='col-12 mt-4'>
    <div className='row'>
        <div className='col-8'>
            <div className="profile-card-title">Add a session{' '}:{''} <span style={{ fontWeight: '400' }}>
                <DatePicker
                    onChange={date => this.setState({ selectedDate: date })}
                    disabledDate={this.disabledDate}
                    />
                    </span>
            </div>
        </div>
        <div className='col-4'>
        <Button className="Add-now-btn mr-3"
        onClick=onClick={this.onSubmitExtra}>
        Submit
        </Button>
        </div>
    </div>
</div>

在点击这提交按钮我们将发送响应到这后端现在

onSubmitExtra = () => {
        const selecteddate  = this.state.selectedDate;
        let submit = selecteddate
        let type = "extra class"
        console.log('submit check=====',submit)
        this.onReschduleClasses(submit, type);

    }

相关问题