Closed jaymeh closed 1 year ago
I could use the following workaround but feels a bit strange that I would have to set the default value for the field to render correctly:
Filepond::make('Assets', 'location')
->rules('required')
->multiple()
->mimesTypes(['image/*'])
->default(fn() => []),
I figured out a way to make the frontend part work here: https://github.com/dcasia/nova-filepond/pull/40, however the handle method receives an encrypted payload since the fillAttribute
is never called, I didnt find a way to override the action logic to be able to make it seamless, basically this line 173 is the one that does the file storing / filling:
But you could manually handle it with something like this:
class TestAction extends Action
{
public function handle(ActionFields $fields, Collection $models)
{
$images = collect($fields->get('images'))->map(Data::fromEncrypted(...));
dd($images);
}
public function fields(NovaRequest $request): array
{
return [
Filepond::make('Images', 'images'),
];
}
}
Illuminate\Support\Collection {#1663 // app/Nova/Actions/TestAction.php:29
#items: array:2 [
0 => DigitalCreative\Filepond\Data\Data {#1659
+path: "nova-filepond/temp/pJvCy73kaoyru3yp/13876436_830590130405601_5111768853454055697_n.jpg"
+filename: "13876436_830590130405601_5111768853454055697_n.jpg"
+disk: "local"
}
1 => DigitalCreative\Filepond\Data\Data {#1654
+path: "nova-filepond/temp/55XulL3NiNRUkJdL/13876436_830590130405601_5111768853454055697_n.jpg"
+filename: "13876436_830590130405601_5111768853454055697_n.jpg"
+disk: "local"
}
]
#escapeWhenCastingToString: false
}
After the upload, you would need to move it from the "temp" dir to a permanent one...
Let me know if this works, or if there are more issues with this approach so I can merge https://github.com/dcasia/nova-filepond/pull/40
Thanks, I just pulled the support actions branch into my codebase and the widget is now rendering as expected.
I am having an issue with the process function though. I think it is somewhere here:
$fields = match (true) {
!is_null($action) => new FieldCollection($resource
->availableActions($request)
->firstWhere('uriKey', $action)
->fields($request)),
default => $resource->creationFields($request),
};
$rules = $fields
->firstWhere('attribute', $attribute)
->getCreationRules($request);
Check the request you should see a new "action" attribute being submitted when you click upload: https://github.com/dcasia/nova-filepond/blob/84deef86e8140290caf66bfca4291132f6c716ee/resources/js/components/FilePondWrapper.vue#L79-L81
Yup, I see that I think the issue is my action has no uri.
Fixed, pull latest code of that branch
Yep, that did it. I also checked over Create, update and replace functionality and all looks to be working ok still. 😃
Lovely, thank you very much!
As a follow on from #27 trying to add a filepond field onto an action leads to a similar issue as described in #38. It appears that the field value is null where the FilePondWrapper expects an array.
files: [ ...props.field.value ],
Just wondering if anything can be done to allow this to function as expected in an Action modal?
Thanks