Fix json serialization (#16558)

* fix copying json fields

* fixed preset filter type

* handling fallback in copyToClipboard function

* add test

* try parsing json content on paste

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
This commit is contained in:
Brainslug
2022-12-15 10:40:43 +01:00
committed by GitHub
parent bbcf76e030
commit 511c8d368b
4 changed files with 135 additions and 5 deletions

View File

@@ -81,6 +81,7 @@ import FormFieldMenu from './form-field-menu.vue';
import { formatFieldFunction } from '@/utils/format-field-function';
import { useClipboard } from '@/composables/use-clipboard';
import FormFieldRawEditor from './form-field-raw-editor.vue';
import { parseJSON } from '@directus/shared/utils';
interface Props {
field: Field;
@@ -178,8 +179,12 @@ function useRaw() {
async function pasteRaw() {
const pastedValue = await pasteFromClipboard();
if (!pastedValue) return;
internalValue.value = pastedValue;
emitValue(pastedValue);
try {
internalValue.value = parseJSON(pastedValue);
} catch (e) {
internalValue.value = pastedValue;
}
emitValue(internalValue.value);
}
return { showRaw, copyRaw, pasteRaw, onRawValueSubmit };