fix: Select with hasMany and localized (#1636)

This commit is contained in:
Dan Ribbens
2022-12-09 09:36:39 -05:00
committed by GitHub
parent b6c597ab5c
commit 756edb858a
3 changed files with 43 additions and 2 deletions

View File

@@ -375,10 +375,13 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
return option;
}),
};
const schemaToReturn = localizeSchema(field, baseSchema, config.localization);
schema.add({
[field.name]: field.hasMany ? [schemaToReturn] : schemaToReturn,
[field.name]: localizeSchema(
field,
field.hasMany ? [baseSchema] : baseSchema,
config.localization,
),
});
},
blocks: (field: BlockField, schema: Schema, config: SanitizedConfig, buildSchemaOptions: BuildSchemaOptions): void => {

View File

@@ -80,6 +80,22 @@ const SelectFields: CollectionConfig = {
},
],
},
{
name: 'selectHasManyLocalized',
type: 'select',
hasMany: true,
localized: true,
options: [
{
label: 'Value One',
value: 'one',
},
{
label: 'Value Two',
value: 'two',
},
],
},
{
name: 'selectI18n',
type: 'select',

View File

@@ -40,6 +40,28 @@ describe('Fields', () => {
});
});
describe('select', () => {
let doc;
beforeAll(async () => {
const { id } = await payload.create({
collection: 'select-fields',
locale: 'en',
data: {
selectHasManyLocalized: ['one', 'two'],
},
});
doc = await payload.findByID({
collection: 'select-fields',
locale: 'all',
id,
});
});
it('creates with hasMany localized', () => {
expect(doc.selectHasManyLocalized.en).toEqual(['one', 'two']);
});
});
describe('number', () => {
let doc;
beforeAll(async () => {