i am getting data in antd table using json data.Now click on a table row iam getting the data in a Modal.Now i want to call same modal on click on register button with empty data?
Here my sample data for StudentTable
showModal = () => {
this.setState({
visible: true,
});
}
onOk = (e) => {
this.setState({
visible: false,
})
}
onCancel = (e) => {
console.log(e);
this.setState({
visible: false
})
}
rowClick = (record, rowIndex) => {
alert("student id...." + record.id)
alert(JSON.stringify(record))
this.showModal();
this.setState({
StudentData: record
})
}
render() {
return (
<div>
<div align="right">
<Button type="primary" onClick={this.showModal}>Register</Button>
</div>
<h2>Student Data</h2>
<Table
dataSource={data}
columns={this.state.columns}
pagination={{ pageSize: 5 }}
rowKey={record => record.id}
onRow={(record, rowIndex) => {
return {
onClick: (event) => this.rowClick(record, rowIndex)
}
}}
/>
<NewModal visible={this.state.visible}
onOk={this.onOk}
onCancel={this.onCancel}
StudentData={this.state.StudentData}
/>
</div>
)
}
i have a NewModal. iam getting the data on a table rowClick using mapPropsValues.Now i want to call same Modal with empty data?If i click on a table row call same modal i am getting the data?Now How to get empty form click on Register button using same modal?
my modal has following code?
import React from 'react'
import {
Modal
} from 'antd'
import FormikApollo from "./FormikForm"
class NewModal extends React.Component {
state = {
visible: this.props.visible
}
render() {
const { StudentData} = this.props
console.log(this.props.StudentData)
return (
<Modal
title="Basic Modal"
visible={this.props.visible}
onOk={this.props.onOk}
onCancel={this.props.onCancel}
onCreate={this.handleCreate}
>
<FormikApollo StudentData={this.props.StudentData}/>
</Modal>
)
}
}
export default NewModal
And iam getting the form data using formik with antd component.Now i want to call same modal what i get click on a table row with empty form click on a register button?
<Form onSubmit={handleSubmit}>
<Row gutter={4}>
<Col span={12} push={5}>
<Field
name="id"
label="StudentID"
placeholder="Enter a Id"
component={AntInput}
type="text"
formitemlayout={formItemLayout}
/>
<Button type="primary" htmlType="submit">Submit</Button>
</Col>
</Row>
</Form>
</div>
)
}
}
const FormikApp = (withFormik)({
mapPropsToValues: ({StudentData}) => ({
...(StudentData)
}),
validationSchema: Yup.object().shape({
username: Yup.string()
.min(3, "Username must be above 3 characters")
.required("Username is required"),
email: Yup.string()
.email("Invalid Email !!")
.required("Email is required"),
password: Yup.string()
.min(6, "Password must be above 6 characters")
.required("Password is required"),
dateofbirth: Yup.string().required("Date is required")
}),
handleSubmit(values,{resetForm}) {
alert(JSON.stringify(values))
console.log(values)
}
})(FormikApollo)