Skip to content

Commit d70156f

Browse files
hawkeye64rstoenescu
authored andcommitted
feat(docs): QForm docs page (quasarframework#3680)
* initial json api for QSelect * Revert "initial json api for QSelect" This reverts commit 687013f. * feat(docs): QChip * feat(docs): QImg * fix(docs): Fixing markdown tables to fit content Default width of 100% makes tables with 2 columns look horrible. A better compomise if to use "width: fit-content" so the table is only as wide as the data. "max-width: 100%" is used to keep current width should data make the rows greater than 100%. This is especially needed for the "Upgrade guide". * feat(docs): Fixing hydration issues * feat(docs): QForm docs page
1 parent ea2998a commit d70156f

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

docs/src/assets/menu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ const components = [
654654
name: 'Select',
655655
path: 'select'
656656
},
657+
{
658+
name: 'Form',
659+
path: 'form'
660+
},
657661
{
658662
name: 'Radio',
659663
path: 'radio'

docs/src/examples/QForm/Basic.vue

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<template>
2+
<div class="q-pa-md">
3+
4+
<q-form
5+
@submit="onSubmit"
6+
@reset="onReset"
7+
class="q-gutter-md"
8+
>
9+
<q-input
10+
filled
11+
v-model="name"
12+
label="Your name *"
13+
hint="Name and surname"
14+
lazy-rules
15+
:rules="[ val => val && val.length > 0 || 'Please type something']"
16+
/>
17+
18+
<q-input
19+
filled
20+
type="number"
21+
v-model="age"
22+
label="Your age *"
23+
lazy-rules
24+
:rules="[
25+
val => val !== null && val !== '' || 'Please type your age',
26+
val => val > 0 && val < 100 || 'Please type a real age'
27+
]"
28+
/>
29+
30+
<q-toggle v-model="accept" label="I accept the license and terms" />
31+
32+
<div>
33+
<q-btn label="Submit" type="submit" color="primary"/>
34+
<q-btn label="Reset" type="reset" color="primary" flat class="q-ml-sm" />
35+
</div>
36+
37+
</q-form>
38+
39+
</div>
40+
</template>
41+
42+
<script>
43+
export default {
44+
data () {
45+
return {
46+
name: null,
47+
age: null,
48+
49+
accept: false
50+
}
51+
},
52+
53+
methods: {
54+
onSubmit () {
55+
if (this.accept !== true) {
56+
this.$q.notify({
57+
color: 'red-5',
58+
textColor: 'white',
59+
icon: 'fas fa-exclamation-triangle',
60+
message: 'You need to accept the license and terms first'
61+
})
62+
}
63+
else {
64+
this.$q.notify({
65+
color: 'green-4',
66+
textColor: 'white',
67+
icon: 'fas fa-check-circle',
68+
message: 'Submitted'
69+
})
70+
}
71+
},
72+
73+
onReset () {
74+
this.name = null
75+
this.age = null
76+
}
77+
}
78+
}
79+
</script>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Form
3+
related:
4+
- /vue-components/input
5+
- /vue-components/select
6+
---
7+
8+
The QForm component allows you to easily validate child form components that have rules associated with them. To have this done automatically, create a button with type **submit**. Do the same if you wish to tie into **reset**.
9+
10+
```html
11+
<div>
12+
<q-btn label="Submit" type="submit" color="primary"/>
13+
<q-btn label="Reset" type="reset" color="primary" flat class="q-ml-sm" />
14+
</div>
15+
```
16+
17+
Alternatvely, you can give the QForm a ref name and call the `validate` and `resetValidation` functions directly.
18+
19+
```
20+
<q-form ref="myForm" class="q-gutter-md">
21+
22+
// and then in code:
23+
24+
if (this.$refs.myForm.validate()) {
25+
// do something
26+
}
27+
```
28+
29+
## Installation
30+
<doc-installation components="QForm" />
31+
32+
## Usage
33+
34+
<doc-example title="Basic" file="QForm/Basic" />
35+
36+
## QForm API
37+
<doc-api file="QForm" />
38+
39+

0 commit comments

Comments
 (0)