-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathSearch.vue
More file actions
64 lines (59 loc) · 1.46 KB
/
Search.vue
File metadata and controls
64 lines (59 loc) · 1.46 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
<template>
<div class="bar bar-header item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<form action='' :id="formId" >
<input ref="input" type="search" :placeholder="placeholder" :value="value" @change="updateValue($event.target.value)">
</form>
</label>
<button class="button button-clear button-positive"
@click='cancel()' v-text="cancelText">
</button>
</div>
</template>
<script>
export default {
props: {
value: {
type: String,
required: true
},
placeholder: {
type: String,
default: 'Search'
},
cancelText: {
type: String,
default: 'Cancel'
},
onSearch: Function,
onCancel: Function
},
data() {
return {
formId: 'von-search-' + Math.random().toString(36).substring(3, 6)
}
},
mounted() {
document.getElementById(this.formId).onsubmit = this.search
},
methods: {
search(e) {
e.preventDefault()
let search = document.querySelector('#' + this.formId + ' > [type=search]')
search.blur()
if (this.onSearch) this.onSearch()
},
cancel() {
if (this.onCancel) {
this.$refs.input.value = ''
this.onCancel()
}
},
updateValue(value) {
this.$refs.input.value = value,
this.$emit('input', value)
}
}
}
</script>