You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-form/demo/parallel-form.js

86 lines
1.5 KiB

/* eslint react/no-multi-comp:0, no-console:0 */
import { createForm } from '../index'
import { regionStyle } from './styles'
import { Switch } from 'ant-design-vue'
const TopForm = {
props: {
form: Object,
},
render () {
const { getFieldProps } = this.form
return (
<div style={regionStyle}>
<div>has email?
</div>
<div>
<Switch
{...getFieldProps('on', { initialValue: true, valuePropName: 'checked' })}/>
</div>
</div>
)
},
}
const BottomForm = {
props: {
form: Object,
on: Boolean,
},
render () {
const { form } = this
const on = form.getFieldValue('on')
const style = {
...regionStyle,
display: on ? 'block' : 'none',
}
return (
<div style={style}>
<div>email:</div>
<div>
<input {...form.getFieldProps('email', { rules: [{ type: 'email' }], hidden: !on })}/>
</div>
</div>
)
},
}
const Form = {
props: {
form: Object,
},
methods: {
onSubmit (e) {
e.preventDefault()
console.log(this.form.getFieldsValue())
},
},
render () {
const { form } = this
return (
<div>
<TopForm form={form}/>
<BottomForm form={form}/>
<div style={regionStyle}>
<button onClick={this.onSubmit}>submit</button>
</div>
</div>
)
},
}
const NewForm = createForm()(Form)
export default {
render () {
return (
<div>
<h2>parallel form</h2>
<NewForm/>
</div>
)
},
}