Fixed saving of a cleared number value (#412)
* Fixed saving of a cleared number value * fix: clearing saved number for a localized field Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
@@ -84,7 +84,6 @@ const LocalizedPosts: CollectionConfig = {
|
||||
name: 'priority',
|
||||
label: 'Priority',
|
||||
type: 'number',
|
||||
required: true,
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -137,7 +137,7 @@ describe('Collections - REST', () => {
|
||||
description: updatedDesc,
|
||||
richText: updatedRichText,
|
||||
nonLocalizedArray: updatedNonLocalizedArray,
|
||||
priority: 1,
|
||||
priority: '',
|
||||
}),
|
||||
headers,
|
||||
method: 'put',
|
||||
@@ -147,6 +147,7 @@ describe('Collections - REST', () => {
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(data.doc.description).toBe(updatedDesc);
|
||||
expect(data.doc.priority).not.toStrictEqual(1);
|
||||
expect(data.doc.nonLocalizedArray).toHaveLength(2);
|
||||
expect(data.doc.richText[0].children[0].text).toBe('english update');
|
||||
|
||||
|
||||
@@ -109,7 +109,8 @@ const traverseFields = (args: Arguments): void => {
|
||||
}
|
||||
|
||||
if (field.type === 'number' && typeof data[field.name] === 'string') {
|
||||
dataCopy[field.name] = parseFloat(data[field.name]);
|
||||
const trimmed = data[field.name].trim();
|
||||
dataCopy[field.name] = (trimmed.length === 0) ? null : parseFloat(trimmed);
|
||||
}
|
||||
|
||||
if (fieldAffectsData(field) && field.name === 'id') {
|
||||
@@ -173,7 +174,7 @@ const traverseFields = (args: Arguments): void => {
|
||||
let valueToSet;
|
||||
|
||||
if (localeID === locale) {
|
||||
if (data[field.name]) {
|
||||
if (typeof data[field.name] !== 'undefined') {
|
||||
valueToSet = data[field.name];
|
||||
} else if (docWithLocales?.[field.name]?.[localeID]) {
|
||||
valueToSet = docWithLocales?.[field.name]?.[localeID];
|
||||
|
||||
Reference in New Issue
Block a user