title: How to hide Django form fields using JavaScript, Jquery etc
body: <p>I would like to dynamically 
  hide form fields. The user should be able to select the component type, which could be a VALVE in which case the user should specify the Kv value and the DI and length fields should be hidden. Or the user could select the PIPE component type in which case the user should specify the inner diameter (DI) and length of the pipe and the k_v field should be hidden.</p>
  
  <p>The model is defined as follows:</p>
  
  <pre><code>class Component(models.Model):
  
  COMPONENT_TYPE_CHOICES = (
      (1, 'k_v'),
      (2, 'pipe')
  )
  
  circuit                     = models.ForeignKey('circuit.Circuit', related_name='components', on_delete=models.CASCADE)
  component_type              = models.IntegerField(default=1, choices = COMPONENT_TYPE_CHOICES)
  component_name              = models.CharField(max_length=200)
  branch_number_collectors    = models.IntegerField(default=4)
  
  # Hide if component_type==2 
  k_v                         = models.FloatField(default=1)
  
  # Hide if component_type==1
  DI                         = models.FloatField(default=0.025)
  length                      = models.FloatField(default=1)
  
  # Calculated properties
  branch_volumetric_flow_rate = models.FloatField(default=0)
  branch_mass_flow_rate       = models.FloatField(default=0)
  
  velocity                    = models.FloatField(default=0)
  reynolds                    = models.FloatField(default=0)
  friction_coefficient        = models.FloatField(default=0)
  pressure_loss               = models.FloatField(default=0)
  
  @classmethod
  def create( cls, 
              circuit,
              ...,
  </code></pre>
  
  <p>The forms.py is as follows:</p>
  
  <pre><code>class ComponentForm(forms.ModelForm):
      class Meta:
          model = Component
          fields = [
              'component_type',
              'component_name',
              'branch_number_collectors',
              'k_v',
              'DI',
              'length'
          ]
  </code></pre>
  
  <p>The simplified Django template is as follows:</p>
  
  <pre><code>{% block content %}
  &lt;form method='POST'&gt; {% csrf_token %}
      {{ form.as_p }}
      &lt;button type='submit'&gt;Save&lt;/button&gt;
  &lt;/form&gt;
  {% endblock %}
  </code></pre>