Open lsmoker opened 5 days ago
allow_email_download
renders to
<input name="allow_email_download" value="true" form="id_bundles.0.bundle" id="id_bundles.0.bundle.allow_email_download">
Also, help_text
is not hidden when it should be.
please also try with attrs={'df-show': ".allow_email_download"},
. I am wonderning why the BooleanField
is not rendered as checkbox.
Thanks. I tried using attrs={'df-show': ".allow_email_download"},
(which seems more correct) as well as overriding the widget to CheckboxInput
(which appears to be the default for BooleanField
anyway). Unfortunately, neither of those changes made it work for me.
I did find that commenting out action='activate("apply")',
made the show/hide toggle work as expected (although the button became non-functional obviously) - that seems like a deep Javascript thing...
I did make some discoveries...
So there is more complexity in my app than my example above shows. allow_email_download
is actually in a form inside a collection, so the path (of the first sibling) is bundles.0.bundle.allow_email_download
. If I use attrs={'df-show': "bundles.0.bundle.allow_email_download"},
, visibility works correctly(!), while only using .allow_email_download
on the email_recipients
field works fine...
I also found that if allow_email_download
is hidden with widget.HiddenInput
, then it's not found by evalVisibility
. For now, I'm using CSS - display: None
to hide it.
Stepping back, what I'm trying to do is use df-show
/df-hide
to respect Django permissions for certain fields/fieldsets on the form collection. I added a field (allow_email_download
) to the main form and used get_initial
in the collection view to set it to True if the user has the permission, then used df-show
to control its visibility.
I also found that if allow_email_download is hidden with widget.HiddenInput, then it's not found by evalVisibility. For now, I'm using CSS - display: None to hide it.
Using display: none
removes the possibility to focus a field and maybe other features. In such situations I therefore reduce the size to 1x1px and use invisible colors.
This particular field is not intended for any user interaction since I'm using it to get the permission from the view to the df-show
attribute of recipients_button
. Would that break needed features?
Or, is there a better way to show/hide a field based on permissions?
For some reason, the
df-show
attr on anActivator
field doesn't work for me. Thehidden
attribute is always added. For other field types,df-show
works fine.In the code below,
recipients_button
is always hidden regardless of the value ofallow_email_download
(I even hacked some js to see if it could be worked around - no go), whileemail_recipients
behaves as expected.When I get time, I can do more testing for a better report.