Form, not showing or greying out a field

Hi all,

Im working on a project where im offering the user a form to fill in. The form contains:

class MaakGegevensdrager(forms.ModelForm):
    class Meta:
        model = models.Gegevensdrager
        fields = ['gegevensdrager_soortsocode','Merk_Type', 'serienummer', 'imei', 'status_onderzoek']```

Translation: soortsocode= item kind, brand and type, serialnumber, imei and status investigation. I would like to the following: 
IF the item kind is not a smartphone; i want to grey out the IMEI-number field. Or set a default value. 
I have read some documentation about initial and for looping the form, but cant figure it out. 
This is my html: 

<div class = "overzichtgoederenrechts">
    <div class="split right">
        <div class="col-6">
            <div class="card">
                    <div h5 class="card-header-maak-gegevensdrager">Maak Hier een Nieuwe Gegevensdrager</div>
                    <div class="card-body">
                        <form class="MaakGegevensdrager"action="{% url 'detailzaak' zaak.id %}"method="post">
                        {% csrf_token %}
                            <table>
                            {{ form.as_table }}
                                </table>
                        <button type="submit"class="btn btn-success">Aanmaken</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
This is the view;

@login_required(login_url=‘home’)
def detailzaak(request, id_zaak):
zaakref = Zaak.objects.all().filter(id=id_zaak)
goederenzaak = Gegevensdrager.objects.all().filter(zaakid=id_zaak)
zaak = Zaak.objects.get(id=id_zaak)
#soortengoed = GegevensdragerSoort.objects.all().filter(socode=‘3’)

Maak gegevensdrager hier invoegen!

if request.method == ‘POST’:
form = forms.MaakGegevensdrager(request.POST)
if form.is_valid():
tijdelijk = form.save(commit=False)
tijdelijk.zaakid = zaakref[0]
#tijdelijk.gegevensdrager_soortsocode = soortengoed
tijdelijk.save()

     # hier de juiste redirect nog toevoegen
     return redirect('detailzaak', id_zaak)
     #return redirect('detailzaak', id_zaak)

else:
form = forms.MaakGegevensdrager()

return render(request, ‘goederenoverzichtzaak.html’, {‘zaakref’: zaakref , ‘goederenzaak’: goederenzaak , ‘zaak’:zaak, ‘form’: form})


Anyone who can give me some insight or help?
I was thinking about doing the following in the html;

for field in form.as_table:     
      if field.gegevensdrager_soortsocode =! 'Smartphone': 

           field.IMEI = '#'

Are you wanting this field greyed out when the form is built/rendered, or is this an action that occurs while the form is being viewed on the user’s browser?

If the former, you can set the disabled attribute on that field in the form in the __init__ method. If the latter, you’d need to use some JavaScript to do that on some action being taken in the browser.

I would like the Imei field to be greyed out when the user selects an item kind NOT a smartphone. So this will need JavaScript if I understand correctly?

That is correct. You can tie a change action to the selection field to check to see if something other than smartphone was selected, then change the IMEI field accordingly.

Poeh, no chance that there is an easy fix similar to this option. I havnt got javascript knowledge whatsoever…