mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 17:26:11 +00:00
Merge pull request #14588 from wusuopu/fix-edit-json-field
This commit is contained in:
commit
70d7bbcb53
@ -12,14 +12,14 @@ const formatContentTypeData = (data, ct, composSchema) => {
|
|||||||
const compoUid = getOtherInfos(schema, [current, 'component']);
|
const compoUid = getOtherInfos(schema, [current, 'component']);
|
||||||
const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
|
const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
|
||||||
|
|
||||||
if (!value) {
|
if (type === 'json' && value !== undefined) {
|
||||||
acc[current] = value;
|
acc[current] = JSON.stringify(value, null, 2);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'json') {
|
if (!value) {
|
||||||
acc[current] = JSON.stringify(value, null, 2);
|
acc[current] = value;
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
|
|||||||
dz: { type: 'dynamiczone', components: ['compos.sub-compo'] },
|
dz: { type: 'dynamiczone', components: ['compos.sub-compo'] },
|
||||||
jsonString: { type: 'json' },
|
jsonString: { type: 'json' },
|
||||||
jsonObject: { type: 'json' },
|
jsonObject: { type: 'json' },
|
||||||
|
jsonBool: { type: 'json' },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -119,6 +120,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
|
|||||||
],
|
],
|
||||||
jsonString: 'hello',
|
jsonString: 'hello',
|
||||||
jsonObject: { hello: true },
|
jsonObject: { hello: true },
|
||||||
|
jsonBool: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
@ -136,6 +138,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => {
|
|||||||
],
|
],
|
||||||
jsonString: '"hello"',
|
jsonString: '"hello"',
|
||||||
jsonObject: '{\n "hello": true\n}',
|
jsonObject: '{\n "hello": true\n}',
|
||||||
|
jsonBool: 'false',
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(formatContentTypeData(data, contentType, components)).toEqual(expected);
|
expect(formatContentTypeData(data, contentType, components)).toEqual(expected);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user