-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[WIP] Introduce form_with #25197 #25560
[WIP] Introduce form_with #25197 #25560
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for making headway on this! ❤️ I'm going to try to review it in the coming days. Since this PR potentially has a large footprint let's keep it to just @dhh's original examples. Then we get a foundation to build on in other PRs. Thoughts? |
8fcec4a
to
8cfcb76
Compare
…es, with new scope option.
352c2f0
to
5625ce8
Compare
8f399ec
to
439b3f2
Compare
b54a26a
to
a26e71d
Compare
1f7400a
to
e88d0cb
Compare
47bcb36
to
8d4aa7b
Compare
7fd63b7
to
00afa34
Compare
4ff1bfc
to
6bf37ab
Compare
@kaspth I completed work on comments from CR, improved code style in general and remove unused code. I also added support for radio buttons and nested fields. I am trying not to grow this PR too big. I think functionality wise it is ~80% through. Test wise ~40%. What could be postpone to next PRs:
What I would finish in this PR are form_with itself tests. Just to make sure basic use cases are covered. Looking forward to get feedback. |
Oh, yeah, Only got to respond to your comments today, I'll check back in on the tests soon 😁 |
I have a feeling that we are undoing all work I did in #4488. The point of creating reusable classes in #4488 was to make easier to extend existing inputs and create news inputs in both the normal workflow or using form builders like Simple Form. I had a dream to one day make Rails default form builder extensible enough to things like I believe it is possible and better to the framework at long term to reuse the classes created in #4488. Even more that the problem we are trying to solve is more a DSL problem than an implementation problem. Right now we have two different DSLs to build forms depending if we have an object or not. Those two different DSLs already shares the same implementation. We are creating a new DSL with a new implementation to solve and we will end up with three DSLs and two implementations. I'd focus on the problem we want to solve, unify the DSLs. Later we can revisit the defaults of current implementation. And if we manage to create a new implementation that satisfies the extensibility requirements of the current, we can go in that direction. |
@rafaelfranca That was my initial thinking, we have this pretty reusable classes family, why not use them? That is how implementation started. Then I encounter challenges:
This logics spans across the whole hierarchy starting from processing arguments to actual logic. Keeping in mind goals: HTML5 compliance and significant simplification of DSL... how would approach it/continue? |
Why they are not HTML5 compliant? AFAIK they are, and if they are not this is something we can fix and we should fix to all implementations. Like I said the goal of the David's proposal is to unify the DSLs. Anything beyond that can be worked but it is future work.
This is the defaults revisiting part of my coment. The tag id will not be needed but name will. The form needs to know how to build automatic names otherwise there is no point of having a DSL if you have to explicitly set everything.
By parts. First, lets focus on the DSL. Having a new DSL building the same HTML code than the actual DSLs. HTML5 compliance is a bug in the previous implementation and in my opinion and needs to be fixed on it too since, like I said, it is expected to be HTML compliant now. Defaults revisiting is the last step and if we do the DSL part right, it can be just a matter of configuring the form builder object. |
@rafaelfranca
the text_field line will translate to There are two things we would like to change here:
So that we have: Now how do we pass this information from new But that would generate quite a lot of if-this-then-that code, i.e. in Tags::TextField:
This same for almost every single Tag and for every single feature. I.e.:
I happy to follow any path you show :) Just let me know how we should approach those design trade-offs. |
Those are exactly what I called defaults revisiting, they don't need to happen now. The first one is unnecessary, having The second one is valid and we don't need to duplicate all the code just to make this happen. Again, lets solve the DSL problem, later we revisit the defaults.
If we want this in our new DSL it is easy to archive without changing anything in the Tags implementation.
This is also not required. Tags is an internal class we don't need to change the interface of the internal class to please our DSLs needs. We can build whatever DSL we want and still use the current interface of the Tags classes. |
Thanks for quick response.
I understand that those point are important defaults to revisit. Please correct if I misinterpret something. I fine to go either way. I guess it is more decision to be made by you, @dhh and @kaspth. I'll be happy to implement whatever makes Rails developers happy :) Just let me know if we're stable on requirements :) |
That decision comes later 😁
We might not need new builders right now. That was @rafaelfranca's point. This PR should just implement a new DSL using the existing Tags classes.
We'll see about that when we revisit defaults in a later PR. Just to reiterate. This PR: add a new DSL that unifies Let me know if you have any questions 😄 |
@marekkirejczyk hey 👋, I opened a new PR to get this going again: #26976 — credited you as well 😉 |
Introducing form_with
Introduce form_with in place of form_for and form_tag.
This is a prototype and the purpose of this PR is to gather feedback.