naive-ui/demo/documentation/components/form/enUS/inline.md

82 lines
1.9 KiB
Markdown
Raw Normal View History

2019-11-01 19:01:55 +08:00
# Inline Form
2020-02-05 12:14:05 +08:00
A Example of inline form.
2019-11-01 19:01:55 +08:00
```html
2020-03-03 14:34:24 +08:00
<n-radio-group v-model="size" name="left-size" style="margin-bottom: 12px;">
<n-radio-button value="small"></n-radio-button>
<n-radio-button value="medium" ></n-radio-button>
<n-radio-button value="large"></n-radio-button>
</n-radio-group>
2019-11-01 19:01:55 +08:00
<n-form
inline
:label-width="80"
2019-11-06 13:48:05 +08:00
:model="formValue"
:rules="rules"
2020-03-03 14:34:24 +08:00
:size="size"
2019-11-01 19:01:55 +08:00
ref="form"
>
<n-form-item label="Name" path="user.name">
<n-input v-model="formValue.user.name" placeholder="Input Name" />
2019-11-01 19:01:55 +08:00
</n-form-item>
<n-form-item label="Age" path="user.age">
<n-input placeholder="Input Age" v-model="formValue.user.age"/>
2019-11-01 19:01:55 +08:00
</n-form-item>
<n-form-item label="Phone" path="phone">
2019-11-01 19:01:55 +08:00
<n-input placeholder="Phone Number" v-model="formValue.phone"/>
</n-form-item>
2020-02-24 15:31:03 +08:00
<n-form-item>
2019-11-01 19:01:55 +08:00
<n-button @click="handleValidateClick">Validate</n-button>
</n-form-item>
</n-form>
<pre>
{{ JSON.stringify(formValue, 0, 2) }}
</pre>
```
```js
export default {
data () {
return {
2020-03-03 14:34:24 +08:00
size: 'medium',
2019-11-01 19:01:55 +08:00
formValue: {
user: {
name: '',
age: ''
},
2019-11-01 19:01:55 +08:00
phone: ''
},
rules: {
user: {
name: {
required: true,
message: 'Please input your name',
trigger: 'blur'
},
age: {
required: true,
message: 'Please input your age',
2019-11-11 13:35:44 +08:00
trigger: ['input', 'blur']
}
},
phone: {
required: true,
message: 'Please input your number',
trigger: ['input']
}
2019-11-01 19:01:55 +08:00
}
}
},
methods: {
handleValidateClick (e) {
e.preventDefault()
2019-11-28 11:05:54 +08:00
this.$refs.form.validate(errors => {
if (!errors) {
this.$NMessage.success('Valid')
} else {
console.log(errors)
2019-11-28 11:05:54 +08:00
this.$NMessage.error('Invalid')
}
})
2019-11-01 19:01:55 +08:00
}
}
}
```