Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/payload/src/admin/forms/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ export type BuildFormStateArgs = {
* @experimental This property is experimental and may change in the future. Use at your own risk.
*/
skipClientConfigAuth?: boolean
/**
* If true, skips checking each field's admin.condition when building form state.
* Useful for bulk edit where sibling data is not document-backed.
*/
skipConditionChecks?: boolean
skipValidation?: boolean
updateLastEdited?: boolean
} & (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const EditManyBulkUploadsDrawerContent: React.FC<
schemaPath: collection.slug,
select,
signal: controller.signal,
skipConditionChecks: true,
skipValidation: !submitted,
})

Expand Down Expand Up @@ -126,6 +127,7 @@ export const EditManyBulkUploadsDrawerContent: React.FC<
return acc
}, {} as SelectType),
),
skipConditionChecks: true,
skipValidation: true,
})

Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/elements/EditMany/DrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const EditManyDrawerContent: React.FC<EditManyDrawerContentProps> = (prop
schemaPath: collection.slug,
select,
signal: controller.signal,
skipConditionChecks: true,
skipValidation: !submitted,
})

Expand Down Expand Up @@ -303,6 +304,7 @@ export const EditManyDrawerContent: React.FC<EditManyDrawerContentProps> = (prop
return acc
}, {} as SelectType),
),
skipConditionChecks: true,
skipValidation: true,
})

Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/forms/fieldSchemasToFormState/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Args = {
schemaPath: string
select?: SelectType
selectMode?: SelectMode
skipConditionChecks?: boolean
skipValidation?: boolean
}

Expand All @@ -101,6 +102,7 @@ export const fieldSchemasToFormState = async ({
schemaPath,
select,
selectMode,
skipConditionChecks,
skipValidation,
}: Args): Promise<FormState> => {
if (!clientFieldSchemaMap && renderFieldFn) {
Expand Down Expand Up @@ -160,6 +162,7 @@ export const fieldSchemasToFormState = async ({
req,
select,
selectMode,
skipConditionChecks,
skipValidation,
state,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/utilities/buildFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const buildFormState = async (
schemaPath = collectionSlug || globalSlug || widgetSlug,
select,
skipClientConfigAuth,
skipConditionChecks,
skipValidation,
updateLastEdited,
} = args
Expand Down Expand Up @@ -228,6 +229,7 @@ export const buildFormState = async (
schemaPath,
select,
selectMode,
skipConditionChecks,
skipValidation,
})

Expand Down
22 changes: 22 additions & 0 deletions test/bulk-edit/collections/Posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ export const PostsCollection: CollectionConfig = {
name: 'description',
type: 'textarea',
},
{
name: 'conditionController',
type: 'select',
options: [
{
label: 'Show',
value: 'show',
},
{
label: 'Hide',
value: 'hide',
},
],
},
{
name: 'conditionalBulkEditField',
type: 'text',
label: 'Conditional Bulk Edit Field',
admin: {
condition: (_, siblingData) => siblingData?.conditionController === 'show',
},
},
{
name: 'fieldWithBeforeInputA1',
type: 'text',
Expand Down
41 changes: 41 additions & 0 deletions test/bulk-edit/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,47 @@ test.describe('Bulk Edit', () => {
await expect(beforeInputB).toHaveCount(1)
await expect(beforeInputB).toBeVisible()
})

test('should render selected field even when admin.condition depends on unselected sibling data', async () => {
await deleteAllPosts()

const updatedValue = 'Updated conditional bulk field'
const { id } = await createPost({ title: 'Conditional Post' })

await page.goto(postsUrl.list)
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('limit=')

const { modal } = await selectAllAndEditMany(page)

await selectInput({
selectLocator: modal.locator('.field-select'),
options: ['Conditional Bulk Edit Field'],
multiSelect: true,
})

const conditionalField = modal.locator('#field-conditionalBulkEditField')
await expect(conditionalField).toBeVisible()

await conditionalField.fill(updatedValue)
await modal.locator('.form-submit button[type="submit"].edit-many__publish').click()

await expect(page.locator('.payload-toast-container .toast-success')).toContainText(
'Updated 1 Post successfully.',
)

const updatedDocQuery = await payload.find({
collection: postsSlug,
where: {
id: {
equals: id,
},
},
depth: 0,
})
const updatedDoc = updatedDocQuery.docs[0]

expect((updatedDoc as any)?.conditionalBulkEditField).toBe(updatedValue)
})
})

async function selectFieldToEdit(
Expand Down