how can i put script on a widget blade view?
i am going to have a widget that will run a script on its view. but no matter where I put the script it didnt work. here's my code:
<x-filament-widgets::widget>
<x-filament::section>
</x-filament::section>
<script>
alert("hey")
</script>
</x-filament-widgets::widget>
any idea why? thanks. this is a custom widget btw and i am using it on a custom page
11 Replies
Alpine.js
A rugged, minimal framework for composing behavior directly in your markup.
@Leandro Ferreira thanks for the response.
this is my script though:
any idea how can i squeze this one to one of my elements just like you did?
i'd rather just put this whole code into a script tag and do x-data="uploadForm" but apparently by script tag doesnt work..
?
well yeah script works now but my form element doesnt seem to find Alpine.data('uploadForm')
This is my use case:
<form x-data="uploadForm" wire:submit="uploadFiles" enctype="multipart/form-data">
This worked all fine until i put it inside the widget
I removed " document.addEventListener('alpine:init', () => {" part and it worked. Would you suggest this?
@Leandro Ferreira
now suddenly it doesnt work anymore
can you help me? @Leandro Ferreira
hum, not sure why
Bro please try to help me i need to make this ready for tomorrow
Your first question was: How can I put the script? I showed you a way to do it. If your code suddenly stops working, I don't know why π
. You should debug it to understand what is happening.
Thank you! How should i approach debugging alpine variables though? I clearly declare the variabke but alpine cant read it somehow
I mean, check the code step by step to understand what is happening..
This is inside a modal, I presume that's not about it though
Okay thanks it was a form element inside another element, that was the reason facepalm
Hi, I need help with uploading a file to a folder with a custom path. I would also like to store more information about the file such as size, disk used, mimetype, how can I map the data to be stored in the database for UploadFile?
I have tried via action, but I would like to do it directly from the form:
Tables\Actions\Action::make('upload_file')->label('Upload File')
->mutateFormDataUsing(function (array $data): array {
$data['folder_id'] = $this->ownerRecord->id;
$data['user_id'] = $this->ownerRecord->id;
$data['disk'] = env('FILESYSTEM_DISK', 'public');
return $data;
})
->action(function (array $data, UserFolder $folder): void {
$file = UserFile::create($data);
$file->folder_id = $folder->id;
$file->mimetype = Storage::disk('public')->mimeType($data['path']);
$file->filesize = Storage::disk('public')->size($data['path']);
$file->save();
})
->form([
Forms\Components\TextInput::make('name')->required(),
FileUpload::make('path')
->storeFileNamesIn('file_name')
->directory('/users/' . $this->ownerRecord->id . '/folders')
])