Closed rasmuscnielsen closed 2 years ago
You can access parentCategory
using the following:
$parentCategory = $data->resource('parentCategory', $data->parentCategory);
PR has been made to improve the documentation: https://github.com/laravel/nova-docs/pull/434
https://nova.laravel.com/docs/4.0/resources/fields.html#accessing-request-resource-ids
The documentation has been updated.
Hi @crynobone - thanks for your feedback.
I've just tested out your solution but unfortunately it does not seem to solve the problem.
When debugging with Xdebug I can see that the dependsOn
closure only executes once, and that FormData.attributes.parentCategory
is NULL
. Again my theory is that because the "Parent Category" select input in the create-form is readonly / disabled, it doesn't broadcast the update when it is set. At least the result is that the dependsOn
callback is never invoked with the parent category set.
I hope you can reproduce the issue on your end too.
Can you provide a reproducing repository to this issue, similar to https://github.com/nova-issues
I hope you can reproduce the issue on your end too.
No, and we already have the feature tested using the example app from https://github.com/laravel/nova-dusk-suite
@crynobone Reproducing repo: https://github.com/rasmuscnielsen/nova-issue-4569
Also a video showing the behavior:
https://user-images.githubusercontent.com/8465957/179232549-28e0ef8b-0380-4e32-8739-7a81d60ca524.mov
@crynobone Any chance to re-open this given my above reproduction repo?
I believe I'm experiencing the same issue in another project at the moment as well, which really impacts the functionality of the dashboard.
It should have been:
if ($data->resource(User::uriKey(), $data->author) !== null) {
Will update the documentation on this details.
It should have been:
if ($data->resource(User::uriKey(), $data->author) !== null) {
Will update the documentation on this details.
Unfortunately this still doesn't solve the described issue on my machine.
Nova/Post.php@57
with if ($data->resource(User::uriKey(), $data->author) !== null) {
Sorry, viaResource
and viaResourceId
is not yet available via $formData->resource()
, will PR this.
In the meantime you can do the following:
Boolean::make('No author')
->help('This field may only be checked when no author is selected.')
->dependsOn(['author'], function (Field $field, NovaRequest $request, FormData $data) {
$authorId = ($request->viaResource === User::uriKey() ? $request->viaResourceId : null) ?? $data->author;
if (! is_null($authorId)) {
$field->hide();
}
})
Thanks @crynobone !
Just tested your solution, and that indeed seems to work! 🎉 Look forward to the PR'ed version that hopefully makes it a bit easier.
Since we're here I just wanted to mention an additional quirk that I've stumbled across. I found that when using a MorphTo
field, there is no easy way to get the selected model class. Is that correct, or just me not finding it in docs or when source diving?
Ie
$source = MorphTo::make('Source')
->required()
->readonly(fn (NovaRequest $request) => $request->isUpdateOrUpdateAttachedRequest())
->types([
GitCommit::class,
GitTag::class,
]),
Text::make('Version')
->onlyOnForms()
->hideWhenUpdating()
->readonly()
->dependsOn([$source], function (Text $version, NovaRequest $request, FormData $form) {
if ($form->source) {
// How to figure out what model was selected?
}
}),
Let me know if you'd rather me creating a separate issue on this. I just thought maybe I'm missing something obvious here 🤔
This has been fixed and is pending next release.
As for you other question, see the following for example: https://github.com/laravel/nova-dusk-suite/blob/9ccd20ec5f4049d003b228b22eb5ba73359ce3d4/app/Nova/Comment.php#L50-L62
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Description:
When field dependsOn a BelongsTo field, it doesn't invoke dependencies when creating viaRelationship. Possible because the dropdown is disabled / readonly.
Detailed steps to reproduce the issue on a fresh Nova installation:
Category
model that has aparent_id
field that links to its own id. Add relationships as follows:Category
Nova resource with the following fieldsCreate an initial category which will be the parent. It should show the boolean field.
Go to the created category and press "Create subcategory". Now the boolean field is still visible, even though it should be hidden as the parent category is set.