Open felixmFlow opened 1 year ago
Same problem here, though I'm confused by your use of an ->if() method, it should be ->dependsOn() ?
But yes, dependent fields don't seem to be working within a flexible layout.
Inserting the example from the Nova docs into a flexible layout doesn't work, the dependent field disappears when the field it depends from changes.
Select::make('Purchase Type', 'type')
->options([
'personal' => 'Personal',
'gift' => 'Gift',
]),
// Recipient field configuration is customized based on purchase type...
Text::make('Recipient')
->readonly()
->dependsOn(
['type'],
function (Text $field, NovaRequest $request, FormData $formData) {
if ($formData->type === 'gift') {
$field->readonly(false)->rules(['required', 'email']);
}
}
),
No error in the console, but the Recipient field does vanish from the HTML.
https://github.com/whitecube/nova-flexible-content/issues/342 mentions fields inside a flexible layout disappearing when they depend on a field outside a flexible layout, but it looks like this occurs when both the field and the dependent field are inside a flexible layout.
One solution, as proposed in 342, is to use https://github.com/alexwenzel/nova-dependency-container. As an added bonus the syntax is a lot nicer too!
update: dependency container doesn't work inside flexible layouts. it functions initially, and values are correctly saved to the database. but fields inside a dependency container are not populated when editing an entry.
I'm using nova 3 though. It looks like this package is only compatible with nova 4 @johnpuddephatt
Same problem using nova-dependency-container
Hello, I have a scenario where i'm adding a conditional field in the layout but for some reason, it's not working.
Flexible::make('custom', 'custom') ->addLayout('', 'wysiwyg', [ Select::make(__('Type'), 'type') ->options([ 'opt1' => 'opt1', 'opt2' => 'opt2' ]),