-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC] Add a modal action whose content is loaded via an HTTP call. #164
Conversation
Thank you for the contribution. I've worked with modal actions, but never implemented them directly in the bundle. In one of my projects, I've implemented modal action type to use primarily with batch actions. In my case, it was showing a form that sends an email or SMS for selected clients. Excuse non-english, it shows selected clients with and without phone number for validation purposes, since you can select anything in batch: For more details, I copied some code into a gist, it may be useful: https://gist.github.com/Kreyu/f58f05acfcf9f8e99cc2d97ecd5bf1e8 Small disclaimer - the modal controller in the gist is responsible for most modals in the application, not only for data table. That's why it contains a logic that checks whether the modal contents should be fetched from an URL or not (its contents may be already rendered). This shouldn't matter here, I think? Not sure why your implementation doesn't work with batch controller - I'll have to check it in a demo app and I'll come back to you (maybe this gist will help a bit 😄).
I think grouping the controllers by theme is perfectly fine! Makes it clear that the controller is strictly related with Bootstrap. However, I suggest changing the default configuration to make the controller disabled by default. Then, developers will be able to opt-in rather than opt-out. This requires a clear note in the documentation. "bootstrap-modal": {
"main": "controllers/bootstrap/modal.js",
"fetch": "eager",
"enabled": false // instead of true
} |
Thanks for the code, it helped me understand the way batch action should work. The problem was that the I don't like the fact that the URL must be absolute, I would have preferred relative ones. What do you think ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should work fine in the current state. That will be the last feature for the 0.26 release. Could you please resolve the conflicts that appeared after merging the dropdown action type and some other fixes? I'll add documentation for the action type in the separate PR. Great job, thank you! 😁
Thank you @alexandre-castelain. I'll add docs in the separate commit. |
Hey !
Here is a POC I created to experiment with the bundle.
The idea is to open a modal with content loaded asynchronously. For instance, this could be used to display the details of a product without redirecting to another page. This is a feature I use frequently in my projects.
I left the
base.html.twig
theme "as is" since I didn’t add any custom JavaScript to it. Depending on the user’s theme, it should be possible to open any kind of modal.Here’s an example of how I implemented it:
This is the way I use it in my test project. As you can see, you can either use the
route
/route_params
options or thehref
one, as discussed in another issue.Unfortunately I didn't manage to get the
BatchAction
working properly. Ideally, I would like to send the selected rows with the HTTP call.The controller’s response must return raw HTML, like this:
And this is the result:
Using this kind of modal, it's even possible to manage a form in a modal. Thanks to a little bit of JavaScript (e.g., Stimulus 👀 ), you can refresh the form, display errors, submit it, and redirect to user properly afterward.
What do you think about it ?
I’m not a huge fan of having the controller in a subfolder. Since it’s tightly coupled to Bootstrap 5, I’m not quite sure how to handle this in the most appropriate way. Any suggestions?