Empower custom forms rendering with Latte

7 years ago

Tomáš Kuba
Member | 17
+
0
-

I would like to propose improving of forms in Nette. The idea is not mine, it came to my mind in a moment when I switched from Symfony back to Nette after 11 months. I am quite convinced that this improvement can move Nette forward. At the end, decision is on Nette community. Feel free to share your opinion and related ideas.

If were in situation when you need to render forms in your own style/theme, you were probably get somewhere around manual rendering or you created own renderer. New label and input Latte macros helps a lot in that situation – but can it be even better? I believe it can…

Necessary intermezzo
If you are not familiar with Symfony, you can believe me, that it has very similar approach to Nette. Key points are:

  • Forms are build as PHP objects (AppForm ~ FromBuilder)
  • Rendering is powered by tempting language (Latte ~ Twig) and back-end developer should not care about UI/HTML in best case
  • Form's life cycle, security and validation are managed by framework (Presenter ~ Controller)

When, what is the difference?
Well, while Nette is rendering form's components using PHP i.e. Html class, Symfony passed this responsibility do Twig(=Latte) templating engine.

Why we would care?
At first place it will separate form logic&model from its appearance/view and it is (in most cases) the right way. On a human level, it will enable UI/Front-end developers, whom are not able to write its own renderer, to customize forms in a very easy and clean way. In case of well done implementation it will also enable:

  • global change of all forms for whole project
  • partial overloading only for necessary forms components/blocks on several levels (pairs, input types, custom types etc.)
  • multiple forms themes in one project

How does it looks like?
Best way to get you in, would be to look right on Symfony Twig template. Even if you are not familiar with Twig, you can recognize, that this template file contains all form parts separated in blocks. FromBuilder just pick up blocks by name and combine them to the final output. Sorry, no big magic here :)

If you are interested more on this custom theming logic can be found in Symfony documentation

Personal conclusion
It is not dramatic change, Nette already has all we need to do it. I have personal (real-life) experience that forms are the most important part of all applications – conversion matters. Anything what will allow more agile approach should be considered.

Thank you for reading up to this place and please, give this idea just 5 minutes. Try to imagine what positive and negative it may cause, like it has been already implemented.

Last edited by Tomáš Kuba (2013-03-21 01:49)

7 years ago

Filip Procházka
Moderator | 4693
+
0
-

Hi,
we've been developing a template file, that could ease the manual rendering of form in template of view/component. It naturally developed into something, I would dare to say better – twitter bootstrap renderer.

But I agree, something like this, not dependent on concrete css framework, should be in Nette by default.

Last edited by Filip Procházka (2013-03-21 01:37)

7 years ago

Tomáš Kuba
Member | 17
+
0
-

Hello Filip,
thanks for support and links. I can see that you have similar idea already year ago – wow! As it seems to me (and I am not hard core Nette guru), your BootstrapRenderer is very close to Symphony implementation. Im happy, that we will not start from the scratch.

My micro-project plan is:

  1. Feedback/support community and goals definition ~60%
  2. Rough specification ~20%
  3. Team setup ~10%
  4. Documentation/Publication ~0%

Because you did such a thing and you still see benefits in “generalization” of Forms theming, I do assume, that it make sense to implement it. I am little aside from Nette community so I would welcome any advice how to proceed such a feature req. to more members, just to get the #1 step done. I have started discussion in English forum but we can move/link it to CZ forum or to Github – not sure about habits in Nette feature processing (pls. link me to RTFD if exists).

Cherry-picks from BotstrapRenderer thread:

Repeating from kick-off post:

  • We should keep HTML/XHTML output editable in Latte as much as possible for UI developers/designers
  • We should threat Forms components “Matryoshka” as close as possible to David's Form decomposition see image