14.03 Custom Directive - Make it Global!
This commit is contained in:
parent
3057951d6a
commit
e2f0100f36
@ -14,28 +14,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { selectAll } from 'src/directives/directive-select-all'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ModalTaskName',
|
name: 'ModalTaskName',
|
||||||
directives: {
|
directives: {
|
||||||
selectAll: {
|
selectAll
|
||||||
// add callback to
|
|
||||||
inserted (el) {
|
|
||||||
const input = el.querySelector('.q-field__native')
|
|
||||||
// could also use this.$refs.name.$refs.input
|
|
||||||
input.addEventListener('focus', () => {
|
|
||||||
if (input.value.length) {
|
|
||||||
input.select()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
'name'
|
'name'
|
||||||
],
|
],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
// content of form does not populate before first render
|
// input.value is null till after first render
|
||||||
|
// defer autofocus till field is populated
|
||||||
this.$refs.name.$refs.input.focus()
|
this.$refs.name.$refs.input.focus()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<q-input
|
<q-input
|
||||||
outlined
|
outlined
|
||||||
v-model="searchField"
|
v-model="searchField"
|
||||||
|
v-select-all
|
||||||
class="col"
|
class="col"
|
||||||
label="Search" >
|
label="Search" >
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
@ -17,9 +18,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState, mapActions } from 'vuex'
|
import { mapState, mapActions } from 'vuex'
|
||||||
|
import { selectAll } from 'src/directives/directive-select-all'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Search',
|
name: 'Search',
|
||||||
|
directives: {
|
||||||
|
selectAll
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState('tasks', ['search']),
|
...mapState('tasks', ['search']),
|
||||||
searchField: {
|
searchField: {
|
||||||
|
10
src/directives/directive-select-all.js
Normal file
10
src/directives/directive-select-all.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export const selectAll = {
|
||||||
|
inserted (el) {
|
||||||
|
const input = el.querySelector('.q-field__native')
|
||||||
|
input.addEventListener('focus', () => {
|
||||||
|
if (input.value.length) {
|
||||||
|
input.select()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user