Skip to content

Commit 97085df

Browse files
committed
feat: add event listeners to all wrapped form components
1 parent f8408eb commit 97085df

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

src/components/form/CInput.vue

-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ export default {
156156
// }
157157
// }
158158
159-
listeners () {
160-
const { input, change, ...listeners } = this.$listeners; // eslint-disable-line no-unused-vars
161-
return listeners;
162-
},
163-
164159
//wrapperComputedProps mixin
165160
// isHorizontal () {
166161
// return Boolean(this.horizontal)

src/components/form/CInputCheckbox.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
description, class: computedClasses}">
44
<template #input>
55
<input
6+
v-on="listeners"
67
v-bind="$attrs"
78
:id="safeId"
89
:type="$options.type"
@@ -33,15 +34,15 @@
3334
</template>
3435

3536
<script>
36-
import { safeId, validationComputedProps } from './form-mixins'
37+
import { sharedComputedProps } from './form-mixins'
3738
import { inputCheckboxProps as props } from './form-props'
3839
import CFormGroup from './CFormGroup'
3940
4041
export default {
4142
name: 'CInputCheckbox',
4243
inheritAttrs: false,
4344
components: { CFormGroup },
44-
mixins: [safeId, validationComputedProps],
45+
mixins: [sharedComputedProps],
4546
props,
4647
// {
4748
// validFeedback: String,

src/components/form/CInputFile.vue

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<template #input>
1616
<input
1717
v-bind="$attrs"
18+
v-on="listeners"
1819
:id="safeId"
1920
:class="inputClasses"
2021
:multiple="multiple"

src/components/form/CSelect.vue

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<template #input>
1717
<select
1818
v-bind="$attrs"
19+
v-on="listeners"
1920
:id="safeId"
2021
:class="inputClasses"
2122
@input="onSelect($event)"

src/components/form/CTextarea.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<template #input>
1414
<textarea
1515
v-bind="$attrs"
16+
v-on="listeners"
1617
:id="safeId"
1718
:class="inputClasses"
1819
:readonly="readonly || plaintext"
@@ -33,7 +34,7 @@
3334

3435
<script>
3536
import CFormGroup from './CFormGroup'
36-
import { textareaProps as props} from './form-props'
37+
import { textareaProps as props } from './form-props'
3738
import * as allFormMixins from './form-mixins'
3839
const mixins = Object.values(allFormMixins)
3940

src/components/form/form-mixins.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
import { makeUid } from '@coreui/utils/src'
22

3-
export const safeId = {
3+
export const sharedComputedProps = {
44
computed: {
5-
safeId () {
5+
computedIsValid() {
6+
if (typeof this.isValid === 'function') {
7+
return this.isValid(this.state)
8+
}
9+
return this.isValid
10+
},
11+
validationClass() {
12+
if (typeof this.computedIsValid === 'boolean') {
13+
return this.computedIsValid ? 'is-valid' : 'is-invalid'
14+
}
15+
},
16+
safeId() {
617
if (this.id || this.$attrs.id) {
718
return this.id || this.$attrs.id
819
}
920
return makeUid()
21+
},
22+
listeners () {
23+
const { input, change, ...listeners } = this.$listeners // eslint-disable-line no-unused-vars
24+
return listeners
1025
}
1126
}
1227
}
@@ -45,22 +60,6 @@ export const wrapperComputedProps = {
4560
}
4661
}
4762

48-
export const validationComputedProps = {
49-
computed: {
50-
computedIsValid () {
51-
if (typeof this.isValid === 'function') {
52-
return this.isValid(this.state)
53-
}
54-
return this.isValid
55-
},
56-
validationClass () {
57-
if (typeof this.computedIsValid === 'boolean') {
58-
return this.computedIsValid ? 'is-valid' : 'is-invalid'
59-
}
60-
}
61-
}
62-
}
63-
6463
export const watchValue = {
6564
watch: {
6665
value (val) {

0 commit comments

Comments
 (0)