Cannot close modal after validation

I have a page that shows a custom column: public function table(Table $table): Table { $user = auth()->user(); $client = Client::query()->where('id', $user->client_id)->first(); return $table ->query($client()->getQuery()) ->columns( [ ViewColumn::make('deadlines') ->label('Deadlines') ->view('filament.tables.columns.client.deadlines') ] ); } In the custom column Blade.php file, there is a modal that includes a header, content, and a Filament button to trigger a function called submit: <x-filament::modal :close-button="true" id="test" width="xl"> <x-slot name="heading"> Heading </x-slot> <!-- Modal Content --> <div> {{ $this->form }} </div> <x-slot name="footer"> <x-filament::button style="float: right;" wire:click="submit()"> Submit </x-filament::button> </x-slot> </x-filament::modal> This is the form: public function form(Form $form): Form { return $form ->schema([ \Filament\Forms\Components\TextInput::make('test_field')->required() ]); } This is the submit function: public function submit(): void { // Validate the data $validatedData = $this->form->validate(); } There is also a button to open the modal on click: x-on:click="$dispatch('open-modal', {id: 'test'})" Issue When I open the modal and click anywhere outside the modal, or on the close icon in the top right corner, the modal closes as expected. However, if I open the modal, leave the TextInput field blank, and click Submit, the submit button shows a spinning icon and then displays a validation error message. After the validation message is displayed, if I try to close the modal, it does not close.
37 Replies
gemini.dev
gemini.devOP5mo ago
Has anyone got any ideas?
awcodes
awcodes5mo ago
Any errors in the dev console? Can’t imagine why livewire would just stop working unless alpine is somehow erroring out.
gemini.dev
gemini.devOP5mo ago
Thanks for the response, just having a look now, bear with me
awcodes
awcodes5mo ago
No rush.
gemini.dev
gemini.devOP5mo ago
Nope, no errors. Even when clicking the close popup button.
No description
gemini.dev
gemini.devOP5mo ago
The click method is still there. I'll have a look to see what it looks like, before I click the "Submit" button. The issue of not closing the popup button, only occurs when clicking the "Submit" button.
No description
gemini.dev
gemini.devOP5mo ago
Appears to be identical
No description
awcodes
awcodes5mo ago
Do you have any of the filament views published?
gemini.dev
gemini.devOP5mo ago
Sorry, how do you mean published?
awcodes
awcodes5mo ago
Can you run php artisan about —filament
gemini.dev
gemini.devOP5mo ago
No description
awcodes
awcodes5mo ago
It’s 2 - Try —only=filament
gemini.dev
gemini.devOP5mo ago
No description
awcodes
awcodes5mo ago
Yep, you have views published.
gemini.dev
gemini.devOP5mo ago
What does this show me, out of curiosity?
awcodes
awcodes5mo ago
If you don’t actually need to override any of the views and don’t want to manually keep them up to date with each release then they shouldn’t be published. I’m guess there is something missing in one of those views in your app that is breaking the functionality.
gemini.dev
gemini.devOP5mo ago
Would it help if I create a sample page and my custom column, and send it over here?
awcodes
awcodes5mo ago
Nope, easy fix is to just delete resources/views/vendor/filament. But make sure they aren’t actually needed if you are working on a team project.
gemini.dev
gemini.devOP5mo ago
One moment
awcodes
awcodes5mo ago
It is never recommended to publish any views from packages unless absolutely necessary and you know what you are doing.
gemini.dev
gemini.devOP5mo ago
In the directory you have specified, I only have one component in there called brand.blade.php. Which is just an image element, that is not releated to this issue.
gemini.dev
gemini.devOP5mo ago
No description
awcodes
awcodes5mo ago
Ok. Maybe that’s what it’s reporting then. Definitely something to note on our side. Could be a bug then. Honestly can’t think of why a validation error would prevent a modal from closing. Can you setup a minimum reproduction repo? I could look into it further. Or file an issue on github.
gemini.dev
gemini.devOP5mo ago
I was just thinking that, yes sure. I'll create a minimum reproduction repo.
awcodes
awcodes5mo ago
Maybe someone will come along too and see something in your code that might be the problem.
gemini.dev
gemini.devOP5mo ago
Hopefully 🙂 I'll let you know once I have it ready Got one created 🙂
gemini.dev
gemini.devOP5mo ago
Here is the repo https://github.com/98gzi/Filament-Issue I have some test data, please ensure to run the database seeders: php artisan db:seed
GitHub
GitHub - 98gzi/Filament-Issue
Contribute to 98gzi/Filament-Issue development by creating an account on GitHub.
awcodes
awcodes5mo ago
Will check it in the morning.
gemini.dev
gemini.devOP5mo ago
Thank you I wonder if, when a validation error occurs, the Livewire component might be re-rendering, which can cause the modal to lose its open state?
awcodes
awcodes5mo ago
Hey @Ed sorry for the delayed response. Here's the situation, it seems like you are getting a little confused on how actions work in relation to livewire components. Try this and remove the modal from your view. Might give you a better idea.
ViewColumn::make('country_towns_custom')
->label('Towns custom column')
->action(
Action::make('update_towns')
->form([
TextInput::make('updateTownName')
->required()
])
)
->view('tables.columns.towns-column')
ViewColumn::make('country_towns_custom')
->label('Towns custom column')
->action(
Action::make('update_towns')
->form([
TextInput::make('updateTownName')
->required()
])
)
->view('tables.columns.towns-column')
gemini.dev
gemini.devOP5mo ago
Hi @awcodes, thanks for your answer and no problem on the delay! I’ve given your suggestion a try. However, it’s causing some bugs (please see the attached recording). Initially, a modal opens and closes as expected, but when I try to open it a second time, a grey overlay appears on the screen without showing the popup. The original code I have is almost what I need, apart from the issue of the modal not closing after validation. The sample provided is a very basic example, but it would be very useful in our project. The idea is to have a column that displays blocks of data (see the attached screenshot image.png), and each block should be clickable to show a modal. I’m unsure if the approach you provided will work, as each block in the column needs to be uniquely identified. The current code:
ViewColumn::make('country_towns_custom')
->label('Towns custom column')
->action(
Action::make('update_towns')
->form([
TextInput::make('updateTownName')
->required()
])
)
ViewColumn::make('country_towns_custom')
->label('Towns custom column')
->action(
Action::make('update_towns')
->form([
TextInput::make('updateTownName')
->required()
])
)
is only adding an action for the entire column, not for each individual block within the column. Hope this makes sense!
No description
gemini.dev
gemini.devOP5mo ago
I think an alternative solution I can try is to dynamically create columns, rather than generating the data within a single column.
awcodes
awcodes5mo ago
Well the biggest problem is that you are trying to do a form directly inside of a table and that won’t work. You may have to have separate livewire components that you can call in another way.
gemini.dev
gemini.devOP5mo ago
@awcodes are nested tables a possibility of being a feature in filamentphp in the future?
No description
awcodes
awcodes5mo ago
I wouldn’t think so. The closest thing at the moment is grouping. I think what you are trying to do is possible, it will just need to be handled from a different approach.
gemini.dev
gemini.devOP5mo ago
I'll keep trying different approaches, like you mentioned a seperate livewire component. I'll keep you updated on here once I have a working solution, may be useful for someone in the future. Figured what the issue is!
gemini.dev
gemini.devOP5mo ago
When I validate the data, the component re-renders, causing the modalId to generate a new unique value. Not a filament issue, this is my error!! -_-
No description
Want results from more Discord servers?
Add your server