Skip to content

Commit 09c11be

Browse files
fix issue of strings not setting switch and checkbox correctly
1 parent c17d697 commit 09c11be

File tree

8 files changed

+49
-15
lines changed

8 files changed

+49
-15
lines changed

src/plugin/components/VInlineCheckbox/VInlineCheckbox.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
>
2323
<BooleanIcons
2424
v-model="truthyModelValue"
25+
:false-value="settings.falseValue"
2526
:icon-false="settings.iconFalse"
2627
:icon-false-color="settings.iconFalseColor"
2728
:icon-false-title="settings.iconFalseTitle"
2829
:icon-true="settings.iconTrue"
2930
:icon-true-color="settings.iconTrueColor"
3031
:icon-true-title="settings.iconTrueTitle"
32+
:true-value="settings.trueValue"
3133
/>
3234
</div>
3335

@@ -386,5 +388,4 @@ onUnmounted(() => {
386388
});
387389
</script>
388390

389-
<style lang="scss" scoped>
390-
</style>
391+
<style lang="scss" scoped></style>

src/plugin/components/VInlineCheckbox/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import type VInlineCheckbox from './VInlineCheckbox.vue';
66
export interface VInlineCheckboxProps extends Omit<SharedProps,
77
'autofocus' | 'truncateLength' | 'truncateSuffix'
88
> {
9-
density?: VCheckbox['$props']['density'];
9+
density?: VCheckbox['density'];
1010
falseIcon?: string | undefined;
1111
trueIcon?: string | undefined;
12+
falseValue?: VCheckbox['falseValue'];
13+
trueValue?: VCheckbox['trueValue'];
1214
}
1315

1416

src/plugin/components/VInlineSwitch/VInlineSwitch.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
>
2323
<BooleanIcons
2424
v-model="truthyModelValue"
25+
:false-value="settings.falseValue"
2526
:icon-false="settings.iconFalse"
2627
:icon-false-color="settings.iconFalseColor"
2728
:icon-false-title="settings.iconFalseTitle"
2829
:icon-true="settings.iconTrue"
2930
:icon-true-color="settings.iconTrueColor"
3031
:icon-true-title="settings.iconTrueTitle"
32+
:true-value="settings.trueValue"
3133
/>
3234
</div>
3335

@@ -372,5 +374,4 @@ onUnmounted(() => {
372374
});
373375
</script>
374376

375-
<style lang="scss" scoped>
376-
</style>
377+
<style lang="scss" scoped></style>

src/plugin/components/VInlineSwitch/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import type VInlineSwitch from './VInlineSwitch.vue';
66
export interface VInlineSwitchProps extends Omit<SharedProps,
77
'autofocus' | 'truncateLength' | 'truncateSuffix'
88
> {
9-
density?: VSwitch['$props']['density'];
10-
falseIcon?: VSwitch['$props']['falseIcon'];
9+
density?: VSwitch['density'];
10+
falseIcon?: VSwitch['falseIcon'];
11+
falseValue?: VSwitch['falseValue'];
12+
trueValue?: VSwitch['trueValue'];
1113
}
1214

1315

src/plugin/components/common/BooleanIcons.vue

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-icon
3-
v-if="modelValue"
3+
v-if="truthyModelValue === true || modelValue === trueValue"
44
class="v-inline-fields--boolean-icons fa-fw"
55
:color="iconTrueColor"
66
:icon="theTrueIcon"
@@ -22,6 +22,7 @@
2222
import type { BooleanIcons } from './';
2323
import { useGetIcon } from '@composables/icons';
2424
import type { IconOptions } from 'vuetify';
25+
import { useTruthyModelValue } from '@composables/helpers';
2526
2627
import { VIcon } from 'vuetify/components';
2728
@@ -36,6 +37,20 @@ watchEffect(() => {
3637
3738
const modelValue = defineModel();
3839
40+
const truthyModelValue = computed(() => useTruthyModelValue({
41+
modelValue,
42+
trueValue: settings.trueValue,
43+
}));
44+
45+
46+
const trueValue = computed(() => {
47+
return settings.trueValue ?? true;
48+
});
49+
50+
// const falseValue = computed(() => {
51+
// return settings.falseValue ?? false;
52+
// });
53+
3954
const theFalseIcon = computed(() => {
4055
return useGetIcon({
4156
icon: settings.iconFalse,
@@ -53,5 +68,4 @@ const theTrueIcon = computed(() => {
5368
});
5469
</script>
5570

56-
<style lang="scss">
57-
</style>
71+
<style lang="scss"></style>

src/plugin/components/common/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export interface BooleanIcons extends
1111
Required<Pick<SharedProps, 'iconFalseColor' | 'iconFalseTitle' | 'iconTrueColor' | 'iconTrueTitle'>>,
1212
Pick<SharedProps,
1313
'iconFalse' |
14-
'iconTrue'
14+
'iconTrue' |
15+
'trueValue' |
16+
'falseValue'
1517
> { };
1618

1719

src/plugin/composables/helpers.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,24 @@ export const useTruthyModelValue: UseTruthyModelValue = (options) => {
6767
return true;
6868
}
6969

70+
if (typeof value === 'string') {
71+
return value;
72+
}
73+
74+
if (value === 1 || value === 0) {
75+
return value;
76+
}
77+
78+
if (value == 1 || value == 0) {
79+
return value;
80+
}
81+
7082
if (value === '1') {
71-
return true;
83+
return '1';
7284
}
7385

7486
if (value == '1') {
75-
return true;
87+
return '1';
7688
}
7789

7890
if (value === true) {

src/plugin/types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export interface SharedProps {
8989
displayPrependInnerIconSize?: VIconSize;
9090
emptyText?: string;
9191
error?: boolean;
92-
falseValue?: boolean | string | undefined;
92+
falseValue?: any;
9393
fieldOnly?: boolean;
9494
hideCancelIcon?: boolean;
9595
hideDetails?: boolean;
@@ -115,7 +115,7 @@ export interface SharedProps {
115115
saveIcon?: string | undefined;
116116
saveIconColor?: string;
117117
tableField?: boolean;
118-
trueValue?: boolean | string | undefined;
118+
trueValue?: any;
119119
truncateLength?: number | undefined;
120120
truncateSuffix?: string | undefined;
121121
underlineColor?: string;

0 commit comments

Comments
 (0)