简体   繁体   English

如何在蚂蚁设计中使用表单项规则比较和验证两个数据选择器的值?

[英]How can I compare and valiudate value of two data picker with form item rules in ant design?

 <Col className='input-forms' xs={24} md={3}> <Form.Item label='start'> {getFieldDecorator('start', { rules: [ { required: true, message: 'Start Date is required' } ] })( <DatePicker format='DD-MMM-YYYY' /> )} </Form.Item> </Col> <Col className='input-forms' xs={24} md={3}> <Form.Item label='end'> {getFieldDecorator('end', { rules: [ { type: 'object', required: true, message: 'End Date is required' }] })( <DatePicker format='DD-MMM-YYYY' /> )} </Form.Item> </Col>

I have two data picker which I want to validate them base on each other : 1:start should not be bigger than the end 2-should not be empty我有两个数据选择器,我想根据彼此验证它们:1:开始不应大于结束 2-不应为空

I have no idea what should I implement invalidation?我不知道我应该如何实现失效?

also I am going to implement by rule我也将按规则实施

<Form.Item
                    name="EndDatetime"
                    label="End Date & Time:"
                    rules={[
                      {
                        required: true,
                        message: "Please select product warranty type!",
                      },
                      {
                        validator: async (_, endDatetime) => {
                          var startDatetime =
                            formRef.current.getFieldValue("StartDatetime");
                          if (startDatetime!=null)
                            if (endDatetime <= startDatetime) {
                              return Promise.reject(
                                "Must be greater than Start Date & Time."
                              );
                            }
                        },
                      },
                    ]}
                  >
                    <DatePicker
                      format={"YYYY-MM-DD hh:mm:ss"}
                      showTime
                      size="large"
                      className="w-100"
                    />
                  </Form.Item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM