“Disabled” option for choiceField - Django

前端 未结 7 1032
别跟我提以往
别跟我提以往 2020-12-24 14:02

I having trouble with a simple question : How to have some \"disabled\" field in a dropdown menu generated via a modelForm and choiceFied in the django Framework ?

相关标签:
7条回答
  • 2020-12-24 14:47

    You can create Choices as mentioned by Bryan like this. In the below options Root 1, Root 2 are automatically disabled and they will look like Group Options

    CHOICES = (
      ('-- Root 1--', 
          (
            ('ELT1', 'ELT1'),
            ('ELT2', 'ELT2'),
            ('ELT3', 'ELT3'),
          )
       ),
      ('-- Root 2--', 
          (
            ('ELT3', 'ELT3'),
            ('ELT4', 'ELT4'),
          )
      ),
    )
    

    The above option will display like this. In the below image, Root 1 and Root 2 are not selectable.

    enter image description here

    Hope this will clear your problem

    -Vikram

    0 讨论(0)
提交回复
热议问题