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
UneditableField renders all select options #817
Comments
This is interesting, but it's missing the code to reproduce. Can you please post a form that repoduces the issue ? Or better yet, fork and add a branch reproducing the issue to https://github.com/django-crispy-forms/crispy-test-project Thanks |
https://github.com/zulrang/crispy-test-project/tree/test-uneditable-field I added an UneditableField to the default form with two choices and an initial. The select is populated on the page with both options. This is a problem when there are many options or (as in my initial issue) it is a list of users. |
I've looked at the templates (crispy_forms/templates/bootstrap{,3,4}/layout/uneditable_field.html) and this is a regression introduced in the bootstrap3 template. The "bootstrap" without version (I assume 2) template just dumps field.value:
Note that this doesn't create a disabled select, it actually doesn't create an input at all. I agree with your reasoning about wanting to eliminate useless and invisible options from the uneditable select, but this bootstrap pre-3 approach is too backwards incompatible. I think it would be best to have a new keyword argument "trim_invisible" for UneditableField that eliminates all but the seen options from an uneditable field. This would keep backwards compatibility and allow you to activate it to get what you want. This trim_invisible option could be implemented as above. Activating trim_invisible by default is not a good idea, as it would break backwards compatibility. It seems to me it's a wide-spread enough usage to create a disabled select using UneditableField, then activate it in javascript as needed. I hope to get feedback from core developers, as there are some design choices I've made that should be double checked. |
I've implemented a trim_invisible_from_select option in this branch: https://github.com/ociule/django-crispy-forms/tree/uneditable_trim_invisible_from_select Can you test it out pls ? To enable, you just set trim_invisible_from_select=True when creating an UneditableField. |
Your implementation sounds sane to me, @ociule. Thanks for helping out. |
Description:
UneditableField still renders entire select dropdown with all options.
I have an UneditableField for an associated User to my model, and for both performance and security reasons, I don't want every user to be rendered to the page when all I want is the current value displayed.
The text was updated successfully, but these errors were encountered: