Django crisp shape, hide / show fields in the template

I am using Crispy-Form and Bootstrap in Django. It works very well. Now, I would like to have a field showing only when another field has an input. Basically I have a multpile select list called A visible, and text field , B, hidden. after the user presses / selects one or more values ​​in A, B, it becomes visible. And if not one is selected, it must become invisible.

Does cripsy have this function or the ability to write JS? Or do I need to write JS in the html page where the form is displayed?

ciao

+4
source share
1 answer

I did something similar once. I set the class to β€œhidden” for the inputs you want to hide first. This can be done by nesting the fields in the Div and assigning css_class. See http://django-crispy-forms.readthedocs.org/en/d-0/layouts.html#universal-layout-objects

Then use javascript to remove the "hidden" class when a specific action occurs.

If you decide to use jQuery, you can use the following function: $ ("Login [name = 'a_hidden_field']"). RemoveClass ('hidden')

+3
source

Source: https://habr.com/ru/post/1448105/


All Articles