Skip to content

Commit 18060e1

Browse files
authored
vue-vuetify: fix how we handle empty values outside a dynamic context (#2481)
* fix how we handle empty values when not in dynamic context (e.g. additionalProperties case) * allow defaulting the schema * update the determineClearValue * remove unnecessary type * revert to the original expression * use the same default time format as react
1 parent b20bc25 commit 18060e1

10 files changed

+22
-19
lines changed

packages/vue-vuetify/dev/views/ExampleView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ const reloadMonacoSchema = () => {
114114
const saveMonacoSchema = () => {
115115
saveMonacoModel(
116116
schemaModel,
117-
(modelValue) => (state.schema = JSON.parse(modelValue)),
117+
(modelValue) =>
118+
(state.schema = modelValue ? JSON.parse(modelValue) : undefined),
118119
'New schema applied',
119120
);
120121
@@ -277,6 +278,10 @@ const handleAction = (action: Action) => {
277278
if (action) {
278279
const newState = action.apply(state);
279280
if (newState) {
281+
if (newState.renderers) {
282+
newState.renderers = markRaw(newState.renderers);
283+
}
284+
280285
Object.assign(state, newState);
281286
}
282287
}

packages/vue-vuetify/src/controls/AnyOfStringOrEnumControlRenderer.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ const controlRenderer = defineComponent({
6363
},
6464
setup(props: RendererProps<ControlElement>) {
6565
const clearValue = determineClearValue('');
66-
return useVuetifyControl(useJsonFormsControl(props), (value) =>
67-
value === null ? clearValue : value,
66+
return useVuetifyControl(
67+
useJsonFormsControl(props),
68+
(value) => value || clearValue,
6869
);
6970
},
7071
computed: {

packages/vue-vuetify/src/controls/DateControlRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const controlRenderer = defineComponent({
141141
142142
const showMenu = ref(false);
143143
144-
const adaptValue = (value: any) => (value === null ? clearValue : value);
144+
const adaptValue = (value: any) => value || clearValue;
145145
const control = useVuetifyControl(useJsonFormsControl(props), adaptValue);
146146
147147
const dateFormat = computed<string>(

packages/vue-vuetify/src/controls/DateTimeControlRenderer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ import {
227227
VWindowItem,
228228
} from 'vuetify/components';
229229
230-
import { vMaska, type MaskOptions, type MaskaDetail } from 'maska';
230+
import { vMaska, type MaskOptions } from 'maska';
231231
import { useDisplay, useLocale } from 'vuetify';
232232
import type { IconValue } from '../icons';
233233
import {
@@ -289,7 +289,7 @@ const controlRenderer = defineComponent({
289289
const t = useTranslator();
290290
const showMenu = ref(false);
291291
const activeTab = ref<'date' | 'time'>('date');
292-
const adaptValue = (value: any) => (value === null ? clearValue : value);
292+
const adaptValue = (value: any) => value || clearValue;
293293
294294
const control = useVuetifyControl(useJsonFormsControl(props), adaptValue);
295295
const { mobile } = useDisplay();
@@ -299,7 +299,7 @@ const controlRenderer = defineComponent({
299299
typeof control.appliedOptions.value.dateTimeFormat == 'string'
300300
? (expandLocaleFormat(control.appliedOptions.value.dateTimeFormat) ??
301301
control.appliedOptions.value.dateTimeFormat)
302-
: (expandLocaleFormat('L LT') ?? 'YYYY-MM-DD H:mm'),
302+
: (expandLocaleFormat('L LT') ?? 'YYYY-MM-DD HH:mm'),
303303
);
304304
305305
const useMask = control.appliedOptions.value.mask !== false;

packages/vue-vuetify/src/controls/MultiStringControlRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const controlRenderer = defineComponent({
6565
const clearValue = determineClearValue('');
6666
return useVuetifyControl(
6767
useJsonFormsControl(props),
68-
(value) => (value === null ? clearValue : value),
68+
(value) => value || clearValue,
6969
300,
7070
);
7171
},

packages/vue-vuetify/src/controls/OneOfEnumControlRenderer.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
} from '@jsonforms/vue';
4040
import { defineComponent } from 'vue';
4141
import { VSelect } from 'vuetify/components';
42-
import { useVuetifyControl } from '../util';
42+
import { determineClearValue, useVuetifyControl } from '../util';
4343
import { default as ControlWrapper } from './ControlWrapper.vue';
4444
import { DisabledIconFocus } from './directives';
4545
@@ -56,8 +56,10 @@ const controlRenderer = defineComponent({
5656
...rendererProps<ControlElement>(),
5757
},
5858
setup(props: RendererProps<ControlElement>) {
59+
const clearValue = determineClearValue('');
60+
5961
return useVuetifyControl(useJsonFormsOneOfEnumControl(props), (value) =>
60-
value !== null ? value : undefined,
62+
value === null ? clearValue : value,
6163
);
6264
},
6365
});

packages/vue-vuetify/src/controls/StringControlRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const controlRenderer = defineComponent({
9999
const clearValue = determineClearValue('');
100100
return useVuetifyControl(
101101
useJsonFormsControl(props),
102-
(value) => (value === null ? clearValue : value),
102+
(value) => value || clearValue,
103103
300,
104104
);
105105
},

packages/vue-vuetify/src/controls/StringMaskControlRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const controlRenderer = defineComponent({
7777
},
7878
setup(props: RendererProps<ControlElement>) {
7979
const clearValue = determineClearValue('');
80-
const adaptValue = (value: any) => (value === null ? clearValue : value);
80+
const adaptValue = (value: any) => value || clearValue;
8181
const control = useVuetifyControl(useJsonFormsControl(props), adaptValue);
8282
8383
const toTokens = (tokenParams: Record<string, any>): MaskTokens => {

packages/vue-vuetify/src/controls/TimeControlRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const controlRenderer = defineComponent({
163163
164164
const showMenu = ref(false);
165165
166-
const adaptValue = (value: any) => (value === null ? clearValue : value);
166+
const adaptValue = (value: any) => value || clearValue;
167167
const control = useVuetifyControl(useJsonFormsControl(props), adaptValue);
168168
169169
const icons = useIcons();

packages/vue-vuetify/src/util/composition.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,7 @@ export const useIcons = () => {
484484
};
485485

486486
export const determineClearValue = (defaultValue: any) => {
487-
const jsonforms = useJsonForms();
488-
489-
const useDefaultValue = inject<boolean>(
490-
IsDynamicPropertyContext,
491-
jsonforms.core?.schema.type !== 'object',
492-
);
487+
const useDefaultValue = inject<boolean>(IsDynamicPropertyContext, false);
493488

494489
// undefined will clear the property from the object
495490
return useDefaultValue ? defaultValue : undefined;

0 commit comments

Comments
 (0)