bootstrap-flask icon indicating copy to clipboard operation
bootstrap-flask copied to clipboard

Improved form rendering

Open madsmtm opened this issue 5 years ago • 15 comments

Updated form rendering to properly use bootstrap v.4, it now also works with nested forms and custom form elements. Basically, I just went to bootstrap/components/forms, and implemented the rendering based on the examples there. I've made the interface a lot more flexible, but and if if you think its needed yet, I can make it backwards compatible

If you approve, I'll attempt to make some documentation

madsmtm avatar Sep 10 '18 08:09 madsmtm

Since you can't easily override macros, I've wrapped them all in a block that you can then extend, the alternative would be this. There's also a block that you can extend if you need to provide rendering of custom form elements

madsmtm avatar Sep 10 '18 08:09 madsmtm

Pull Request Test Coverage Report for Build 37

  • 3 of 4 (75.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-1.7%) to 86.538%

Changes Missing Coverage Covered Lines Changed/Added Lines %
flask_bootstrap/init.py 3 4 75.0%
<!-- Total: 3 4
Files with Coverage Reduction New Missed Lines %
flask_bootstrap/init.py 1 86.54%
<!-- Total: 1
Totals Coverage Status
Change from base Build 28: -1.7%
Covered Lines: 45
Relevant Lines: 52

💛 - Coveralls

coveralls avatar Sep 10 '18 09:09 coveralls

I'm still not really satisfied with how widgets, especially TableWidgets, are rendered inside ListWidgets, I'd like the label & help text to be in a top row if possible

madsmtm avatar Sep 10 '18 12:09 madsmtm

Thanks very much! I will review your code as soon as I have free time.

greyli avatar Sep 12 '18 13:09 greyli

LGTM! Just go ahead to update the docs.

greyli avatar Sep 17 '18 11:09 greyli

I've made the interface a lot more flexible, but and if you think its needed yet, I can make it backward compatible.

Does this PR break something?

greyli avatar Sep 17 '18 11:09 greyli

Does this PR break something?

I've changed the interface of the render_field, render_form macros and removed the form_errors macro. I've also removed the bootstrap_is_hidden_field jinja function, and replaced it with the is_hidden test

madsmtm avatar Sep 17 '18 11:09 madsmtm

IMO, it's a good idea to make it backward compatible.

greyli avatar Sep 17 '18 12:09 greyli

I've tried documenting a little bit, but I'm unsure about the format. Should I:

  • Make a seperate file, where I put information about all the methods, and how to customize the form rendering
  • Only document the single render_form method

Or something in between those two?

madsmtm avatar Sep 17 '18 14:09 madsmtm

I prefer to make a new file.

greyli avatar Sep 17 '18 14:09 greyli

Can we just keep the old keyword arguments (i.e. action, method, extra_classes etc)? Both in the code and the docs. These arguments were commonly used when people rendering a form.

greyli avatar Sep 17 '18 14:09 greyli

If you feel like we should do that, then yes, easily. Which ones do you want to keep precisely, action, method, role, enctype, id, novalidate and extra_classes?

madsmtm avatar Sep 17 '18 14:09 madsmtm

@madsmtm We need to let user transfer easily from Flask—Bootstrap to this project, so I want to keep all of them.

greyli avatar Sep 17 '18 14:09 greyli

Well, but I don't see a reason to update the code, since after I made it backwards compatible, they can, they don't need to do anything. But if you want it added to the docs, I'll be happy to do so, I'm out of time for today though

madsmtm avatar Sep 17 '18 16:09 madsmtm

OK, you are right, just update the docs will be enough.

greyli avatar Sep 18 '18 00:09 greyli