How to remove hidden tag on row in django if specific value was choosen in column in another row
I'm using Django to create site and need to show column only if specific value was choosen on column ie if i choose 'medium' in difficult column 'level' column show up:
forms.py
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit, Column, Row
difficult = (('1', 'low'), ('2', 'medium'), ('3', 'hard'),)
level = (('1', 'bad'), ('2', 'decent'), ('3', 'briliant'),)
class ContactForm(forms.Form):
difficult = forms.ChoiceField(choices=difficult, label='Choose level')
level = forms.ChoiceField(choices=level, label='Choose level')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Row(Column('difficult', css_class='form-group col-md-4 mb-0'), css_class='form-row'),
Row(Column('level', css_class='form-group col-md-4 mb-0'), css_class='form-row', hidden = 'true'),
Submit('submit', 'submit', css_class="btn-success")
)
views.py
from django.shortcuts import render
from .forms import ContactForm
def index(request):
form=ContactForm()
if request.GET:
temp = request.GET['module']
print(temp)
return render(request,'info.html',{'form':form})
info.html
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width" />
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body style="padding:20px;">
<h1 class="mt-2" style="text-align:center;font-weight:bolder;color:steelblue;">Choose</h1>
<hr class="mt-0 mb-4">
{% crispy form form.helper %}
</body>
</html>
I know there must be js since it's tool that work on client side, but have no idea how to use that there.
There's similar question, but there some params and classes outside of provided code that i cant
In finale i want to download a xml file with choosed options after pressing submit button, but i will figure out how do to it after.