react+antd的Form处理

在做项目的时候,碰到一个需求要给后台传除展示在页面的其他内容,这里记录一下.

const changeValue = (value) => {
    switch (value) {
        case 1: form.setFieldsValue({ "driver_class_name": "com.mysql.jdbc.Driver" });
        case 2: form.setFieldsValue({ "driver_class_name": "org.apache.kylin.jdbc.Driver" });
    }
}
const [form] = Form.useForm();

const handleLink = () => {
        const fieldsValue = form.validateFields();
        //fieldsValue即为表单内的值
        fieldsValue.then(values => {
            debugger
            BIApi.datasource.testConnection({ project_id: pro_id }, values as DatasourceInputDTO).then((res) => {
                if (res) {
                    message.success("连接成功");
                } else {
                    message.error("连接失败");
                }
            }).catch(() => {
                message.error("连接失败");
            })
        })
    }
<Form {...formItemLayout}
    form={form}
    onFinish={handleLink}
>
    <Form.Item label="驱动" name="drivers_id" style={{ marginTop: 10 }}
        rules={[
            {
                required: true,
                message: 'Please select or upload the driver!',
            },]
        }
    >
        <Select style={selectWidth} placeholder="请选择驱动" onChange={(value) => changeValue(value)}>
            <Option value={1} key="1">com.mysql.jdbc.Driver</Option>
            <Option value={2} key="2">org.apache.kylin.jdbc.Driver</Option>
        </Select>
        {/* <Upload><Button type="primary">上传</Button></Upload> */}
    </Form.Item>
    <Form.Item label="驱动名称" name="driver_class_name" hidden={true}
        dependencies={['drivers_id']}>
        <Input />
    </Form.Item>
    <Form.Item label="URL" name="url" style={{ marginTop: 10 }}
        rules={[
            {
                required: true,
                message: 'Please input url!',
            },]
        }
    >
        <Input />
    </Form.Item>
</Form>
​

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值