0

I have two pages addressForm.js and index.js. In addressForm.js page the code for Form is written. Sample code shown below.

<Col >
                    <div style={{'height': '45px','display':'flex'}}> 
                    <label style={{'color': '#f5222d', 'paddingTop': '10px','fontFamily': 'SimSun'}}>*</label>&nbsp;
                    <label style={{'width':'74px','paddingTop':'8px'}}>Customer Name:</label>                       
                        <FormItem >
                        {getFieldDecorator('Name', {
                        initialValue: '',
                        rules: [{
                            required: true, 
                            message: (
                              <Tooltip
                                visible={true} placement="topRight"
                                title="Please Input Customer Name"
                              />
                            ),
                        }],
                        })(
                        <Input placeholder="Customer Name" style={{'width':'164px'}} onChange={(e)=>{e.preventDefault(); e.stopPropagation();                                   
                            this.handleChange(0,e, 'Name')}}/>
                        )}                    
                    </FormItem>
                    </div>
                    </Col>

In the index.js page fuctions for the form is written (What to happen when the Submit button is clicked). Sample Code:

handleOk = () => {
    this.props.form.validateFields((err, values) => {
        if (!err) {
          /* Code.......*/
 }
    });
    }

The problem is that the validation is not working (ie.,validation checking is not done and I am getting this error).

Shall I import anything in index.js page to avoid the error?

Jane Fred
  • 1,379
  • 7
  • 23
  • 47

3 Answers3

1

you can solve this issue by trying this code:

class Devices extends React.Component {
   .................
}

Devices = Form.create({})(Devices);
export default Devices;
Rizwan
  • 3,741
  • 2
  • 25
  • 22
0

Something in your props is not being passed in or defined correctly, which is giving the TypeError. It looks like you might need to pass in props explicitly into your handleOk function - its hard to tell though with the snippets provided.

0

From the documentation, form should be decorated by Form.create.

If the form has been decorated by Form.create then it has this.props.form property.

class CustomizedForm extends React.Component {}

CustomizedForm = Form.create({})(CustomizedForm);
Triyugi Narayan Mani
  • 3,039
  • 8
  • 36
  • 56