Change DjangoForm fields using JS

0

class AdditionalForm(forms.ModelForm):
    class Meta:
        model = Additional_information
        fields = [
            'have_disability',
            'name_of_disability'
        ]
    have_disability = forms.ChoiceField(
        label='Você tem alguma deficiência ?', choices=Disability.CHOICES, widget=forms.RadioSelect)
    name_of_disability = forms.CharField(
        label='Qual', max_length=255, required=False)

which is a mirror of the following model :

class Additional_information(models.Model):
    have_disability = models.CharField(
        max_length=50, choices=Disability.CHOICES, verbose_name='Você tem alguma deficiência ?')
    name_of_disability = models.CharField(
        max_length=255, verbose_name='Qual')

    def __str__(self):
        return f'{self.have_disability} {self.name_of_disability}'

js I am using the following code to delete the field name_of_disability :

let userDataInputs = document.querySelectorAll('form input');
if (window.location.pathname === '/cadastrar/dados-complementares') {
    if (userDataInputs[2].checked == true){
        userDataInputs[3].style.display = 'none';
    } else{
        userDataInputs[3].style.display = 'flex';
    }
}

But it is not working and I have tried some things kkkkkk and it is not working. Thanks in advance.

    
asked by anonymous 16.11.2018 / 17:11

0 answers