According to the example in #39 I figured it must be possible to show a block editor conditionally, with a fallback. But it doesn't work (But I feel it should).
@formField('radios', [
'name' => 'type',
'label' => 'Is it a Game?',
'default' => 'no',
'inline' => true,
'options' => [
[
'value' => 'no',
'label' => 'No'
],
[
'value' => 'yes',
'label' => 'Yes'
]
]
])
@component('twill::partials.form.utils._connected_fields', [
'fieldName' => 'type',
'fieldValues' => 'no',
'renderForBlocks' => false
])
@formField('block_editor', [
'blocks' => ['bucket']
])
@endcomponent
@component('twill::partials.form.utils._connected_fields', [
'fieldName' => 'type',
'fieldValues' => 'yes',
'renderForBlocks' => false
])
@formField('block_editor', [
'blocks' => ['bucket_app']
])
@endcomponent
What happens is that the last block_editor bucket_app is shown, and also doesn't change when switching the radio input.
PS: when switching 'renderForBlocks' => false to true, the result is that the whole publishing form disappears and only the grey background of the admin is left.
Hey @madsem,
renderForBlocks only needs to be set to true when using the connected fields component inside a block. I'm not a fan of this variable naming either to be honest!
As for your issue with having multiple block editor conditionally rendered in the same form, this is indeed not possible, but we are working on it at #112!
Hi! My conditional fields do not even showing. I have something like below:
@formField('radios', [
'name' => 'menuable_type',
'label' => 'Links to',
'default' => $item->menuable_type ?? 'App\Models\Page',
'inline' => true,
'options' => [
[
'value' => 'App\Models\Page',
'label' => 'Page'
],
[
'value' => 'App\Models\Post',
'label' => 'Post'
]
]
])
@component('twill::partials.form.utils._connected_fields', [
'fieldName' => 'menuable_type',
'fieldValues' => 'App\Models\Page',
'keepAlive' => false,
])
@formField('browser', [
'moduleName' => 'pages',
'name' => 'page',
'label' => 'Page',
'max' => 1,
'routePrefix' => 'content'
])
@endcomponent
@component('twill::partials.form.utils._connected_fields', [
'fieldName' => 'menuable_type',
'fieldValues' => 'App\Models\Post',
'keepAlive' => false,
])
@formField('browser', [
'moduleName' => 'posts',
'name' => 'post',
'label' => 'Post',
'max' => 1,
'routePrefix' => 'blog'
])
@endcomponent
Neither browsers are shown. I get only the radios displayed. If I do not wrap the "browser" fields inside the "_connected_fields" they show and are functioning.
What I am trying to do is to save a polymorphic relation.
What could be the problem?
Thank you in advance!
I have "solved" this one. If the fieldValues contain backslashes ("\") something breaks up and the isEqual function never returns true ... therefore the components are not shown. After I have replaced the "\" with a "-" ... everything was working as expected. I just need to make sure that I put in DB with "\" instead of "-".