fix: Select with hasMany and localized (#1636)
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user