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
Improve multivalue support #976
base: main
Are you sure you want to change the base?
Conversation
I've had a few thoughts on this over the weekend. There is duplication in render_multi_field and crispy_field, particularly the way that the additional attributes are handled. They also do this in different ways, we should at least adopt the crispy_field way of doing things, I think. I feel consistency is most important. Do we add the additional 'looping' functionality to crispy_field - maybe through an additional attribute which we can catch and do something with. How do we do this in a way which is backwards compatible. Multifield.html needs to be able to render different code depending what field is within the multifield. Most may be straight forward This will be a fairly big change to the multifiled style, so should we need to add a flag for backwards compatibility. |
I've taken the approach to base I've also stripped back the additional CSS styles in this function, we should pass it in via the template. This is a slightly wider point which I'll come back to post 1.9.0. I'd like to make some more progress on using the template packs to pass in CSS styles rather than have them coded into the core application. This will make it easier to decouple the template packs. |
I've made some more progress on this, and I've learnt that 'mulivalue' and 'multifield' has caused me quite some confusion. I'll delete the previous comment as that turned out to be completely wrong! What I've been trying to solve here is 'multivalue' fields. e.g. SplitDateTimeField and this is completely different to the multfield layout object in crispy-forms. I've therefore created a new template for 'multivalue' fields. In addition to what I see as the standard usage of multivalue fields I've also added some support for a single checkbox. However, I've not gone as far as allowing multiple checkbox / radio within a multivalue field. Whilst I've got a couple of remaining tests to fix, here are some images of what it currently looks like. |
Codecov Report
@@ Coverage Diff @@
## master #976 +/- ##
=========================================
+ Coverage 95.62% 96.53% +0.9%
=========================================
Files 24 24
Lines 2768 2797 +29
Branches 244 255 +11
=========================================
+ Hits 2647 2700 +53
+ Misses 79 50 -29
- Partials 42 47 +5
Continue to review full report at Codecov.
|
tidy whitespace and old imports
Hi @carltongibson please could I have some guidance. I'm struggling to understand what is happening with this test.
The html being produced currently is as per below (bs3 template pack). There are two input fields being produced for the Do you have a view on what the expected behaviour is here?
|
I was thinking very long and hard about this problem, and started to wonder why in I did a proof-of-concept code that does two things:
I'm still working on it, but for me the initial results here are what I'd want and I think it solves the issue of adding 'form-control' to widgets. |
Hi @sbutler Thank you for thinking about this. 👍 I also have some thoughts on the piece of code you are referring too (where we add I'd therefore prefer we removed this logic from Appreciate your thoughts. |
Note to self. I wonder if we can loop to a sub template for each sub field rather than trying to fix this in python code. |
This is some early work towards fixing #831 . This isn't much more than a proof of concept as there are many more things to consider, along with tests, documentation etc.
However, I'd appreciate views on if this is a reasonable approach to this problem and if it is worth exploring further.
A few notes:
field.html has been updated to use multifield.html
a new template tag has been created. Most of it is copied from here with a few modifications to get it working for my requirements. This tag allows us to loop over each field within a multifield.
multifield.html iterates over the multifield allowing us to put each
<input>
within a<div>
allowing us to add a col class for bs4 style.