-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX][Form] Provide better front end for Collections #29467
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
Comments
I would really love that, especially as we might be able to fix other sort-of related issues like #27477 The main issue is that all of them require custom javascript that needs to be embedded in the website. I am not sure whether this has been discussed before or whether this is something that symfony wants to do. But so far symfony doesn't do anything with javascript (except the web debug toolbar). |
I think the JS part isn't the biggest issue: that should be simple as requiring one js file. It can be a jQuery file, but since Symfony embraces modern JS code (Encore) it could be a Vue/React/Angular/ES6 file as well. The add/delete buttons (in the Twig templates) are my main issue: that involves custom form themes right now. A great feature if you want to customize your forms, but very hard to understand if you just started with Symfony. |
Another problem with this is that it's not possible to require non-opinionated solution. Symfony would have to choose one of the JS libraries. Or is there something else Symfony can do that can ease the integration of these libraries? |
Exactly that is what I meant will be the biggest issue: not the technical one (that is fairly simple), but the political one: Symfony would – for the first time so far – provide JS for actual production usage. I think that it would be best if this would be a community-provided package, that just implements these helpers / functions. |
The JS part isn't the biggest problem. Symfony de facto already has a opinionated solution: it provides jQuery-scripts in the documentation. For an experienced developer it's easy to replace it by Vue/React/Angular/ES6 code. The JS part is as simple as putting I think adding the buttons (add/remove) to the Twig templates is the most difficult step of getting CollectionTypes working, because it requires Custom Form Rendering. I think Symfony should provide a way to configure those buttons (location, label, classes, etc.) like other fields (i.e.
The alternative to not providing JS is providing a feature (CollectionType) that requires the user to understand custom form rendering or rely on third party bundles. That's not a great Developer Experience IMHO. Adding the buttons to the templates (with some basic configuration options for positioning, label, |
also the HTML/buttons can lead to an opinionated setup; ive seen collections with -/+ (remove/add) buttons below the collection, above the collection, above and below, buttons per entry row. Other buttons that might be required like up/down etc. Eventually adding the HTML/buttons without having them to actually work by default (as there's no JS integration in core), was likely the reason to not include those. I think it's good practice to deal with it in your custom form type once. And keep it tied to the JS handling it. My worry is, we'll try to create a one-size-fits all backend option to render it all, whereas you should "theme" your forms as such. |
I understand the reason to not include actual JS and buttons, but the current situation leads to a form field that doesn't work at all. I understand it's impossible to get a template/script that works for everyone, but at least all other fields do work. For all other form fields we say 'we've got a default template for you, if you want to modify it: here's some basic configuration, use css or try custom form rendering'. But for CollectionType we're saying: 'this doesn't work at all, use custom form rendering to get it working'. I really think we should provide a default way of working and explain how to modify it (like we do for all other fields). |
the other fields dont rely on a JS concept to work. Also is there any real reason to render buttons server side actually 🤔 if you rely on a certain JS implementation, why not inject the expected buttons simply with JS first then? |
I agree with @ro0NL here. Injecting the buttons using JavaScript looks much cleaner to me. So I am going to close here. If anyone wants to work on a reusable solution that could still be published as a separate package. In the future we may still reconsider our decision and integrate such a package into the core component if it proves to be reasonable. |
If you want to get CollectionType to work, you can:
I'm now using MopaBootstrapBundle but I want to get rid of it and use Symfony's own Bootstrap form theme instead. The bundle isn't well maintained and doesn't work with Bootstrap 4: phiamo/MopaBootstrapBundle#1222
I think using CollectionTypes should be easier. Customizing Form Rendering shouldn't be needed to get it working. I've got an application with 100+ forms and use custom templates rarely, because most Form types work perfectly with the default templates.
The text was updated successfully, but these errors were encountered: