Reputation: 4271
i'm using Crispy-Form and Bootstrap within Django. It works very well.
Now, i would like to have a field showing only when another field has input.
Basically i've a multpile select list
called A visible, and a text field
, B, hidden.
once the the user focus/select one or more value in A, B should become visible. And if none are selected it should become invisible.
Does cripsy form have this feature or the possibility to write the JS? Or do i've to write the JS in the html page where the form is rendered?
ciao
Upvotes: 6
Views: 5166
Reputation: 1358
I've done something similar once. I assigned a class 'hidden' to the inputs that you want to be initially hidden. This can be done by nesting the fields in a Div, and assigning a 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 certain action occurs.
If you decide to use jQuery, you can use the following function: $("input[name='a_hidden_field']").removeClass('hidden')
Upvotes: 4