forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidationAsync.vue
More file actions
66 lines (58 loc) · 1.53 KB
/
ValidationAsync.vue
File metadata and controls
66 lines (58 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
<div class="q-pa-md" style="max-width: 350px">
<q-field
ref="fieldRef"
filled
:model-value="slider"
hint="Pick between 10 and 60"
:rules="[ myRule ]"
>
<template v-slot:control>
<q-slider
v-model="slider"
:min="0"
:max="100"
label
label-always
class="q-mt-lg"
style="width: 200px"
/>
</template>
</q-field>
<q-btn class="q-mt-sm" label="Reset Validation" @click="reset" color="primary"/>
</div>
</template>
<script>
import { ref } from 'vue'
export default {
setup () {
const fieldRef = ref(null)
return {
slider: ref(10),
fieldRef,
myRule (val) {
// simulating a delay
return new Promise((resolve, reject) => {
setTimeout(() => {
// call
// resolve(true)
// --> content is valid
// resolve(false)
// --> content is NOT valid, no error message
// resolve(error_message)
// --> content is NOT valid, we have error message
resolve((val >= 10 && val <= 60) || 'Please set value to maximum 60')
// calling reject(...) will also mark the input
// as having an error, but there will not be any
// error message displayed below the input
// (only in browser console)
}, 1000)
})
},
reset () {
fieldRef.value.resetValidation()
}
}
}
}
</script>