@744383324629237872
this worked out!
import { Block } from "payload/types"
export const Link: Block = {
slug: 'link',
labels: {
singular: 'Link',
plural: 'Links',
},
fields: [
{
name: 'text',
label: 'Text',
type: 'text',
},
{
name: 'url',
label: 'URL',
type: 'text',
},
{
name: 'page',
type: 'relationship',
relationTo: ['pages'],
admin: {
condition: (data, siblingData) => {
return siblingData?.typeSelect === 'relationship' ? true : false
}
},
},
{
name: 'typeSelect',
label: 'Type',
type: 'select',
defaultValue: 'default',
options: [
{
label: 'Default',
value: 'default',
},
{
label: 'Relationship',
value: 'relationship',
}
],
},
]
}
{
name: 'page',
type: 'relationship',
relationTo: ['pages'],
admin: {
condition: (data) => {
console.log(data);
// return data.typeSelect === 'relationship' ? true : false
if (data.typeSelect === 'relationship') {
return true;
} else {
return false;
}
}
},
},
{
name: 'typeSelect',
label: 'Type',
type: 'select',
defaultValue: 'default',
options: [
{
label: 'Default',
value: 'default',
},
{
label: 'Relationship',
value: 'relationship',
}
],
},
the condition is working correctlhy the only problem is that it not display the field on changing the value of typeSelect
I don't know how i could incroporate that
but it still not works
import { Block } from "payload/types"
export const Link: Block = {
slug: 'link',
labels: {
singular: 'Link',
plural: 'Links',
},
fields: [
{
name: 'text',
label: 'Text',
type: 'text',
},
{
name: 'url',
label: 'URL',
type: 'text',
},
{
name: 'page',
type: 'relationship',
relationTo: ['pages'],
admin: {
condition: (data) => {
let display = false
if (data.typeSelect === 'relationship') {
display = true
}
return display
}
},
},
{
name: 'typeSelect',
label: 'Type',
type: 'select',
options: [
{
label: 'Default',
value: 'default',
},
{
label: 'Relationship',
value: 'relationship',
}
],
},
]
}
if i do
data.typeSelect === 'relationship'
it not shows then, to show you i've added the
!
yes it didn't work
Does that not work?
Ummm I think in my case i want to control its display according to select
if i selected option
relationship
- I want it to be displayed
and if default is selected - I want it to be hidden
import { Block } from "payload/types"
export const Link: Block = {
slug: 'link',
labels: {
singular: 'Link',
plural: 'Links',
},
fields: [
{
name: 'text',
label: 'Text',
type: 'text',
},
{
name: 'url',
label: 'URL',
type: 'text',
},
{
name: 'page',
type: 'relationship',
relationTo: ['pages'],
admin: {
condition: (data, siblingData) => {
if (data.typeSelect === 'relationship') {
console.log(data.typeSelect === 'relationship');
return true
} else {
console.log(data.typeSelect === 'relationship')
return false
}
}
},
},
{
name: 'typeSelect',
label: 'Type',
type: 'select',
options: [
{
label: 'Default',
value: 'default',
},
{
label: 'Relationship',
value: 'relationship',
},
],
},
]
}
Star
Discord
online
Get dedicated engineering support directly from the Payload team.