1+ from typing import List , Tuple
2+
13from django import forms
24from django .utils .translation import gettext_lazy as _
35from wagtail .core import blocks
@@ -53,7 +55,13 @@ class DropdownField(BaseField):
5355
5456 def get_options (self , block_value ):
5557 options = super ().get_options (block_value )
56- choices = [(c .strip (), c .strip ()) for c in block_value .get ("choices" )]
58+ choices : List [Tuple [str , str ]] = []
59+ for c in block_value .get ("choices" ):
60+ if isinstance (c , dict ) and c .get ("value" ):
61+ choices .append ((c ["value" ].strip (), c ["value" ].strip ()))
62+ else :
63+ choices .append ((c .strip (), c .strip ()))
64+
5765 if block_value .get ("empty_label" ):
5866 choices .insert (0 , ("" , block_value .get ("empty_label" )))
5967 options .update ({"choices" : choices })
@@ -80,7 +88,12 @@ class MultiSelectField(BaseField):
8088
8189 def get_options (self , block_value ):
8290 options = super ().get_options (block_value )
83- choices = [(c .strip (), c .strip ()) for c in block_value .get ("choices" )]
91+ choices : List [Tuple [str , str ]] = []
92+ for c in block_value .get ("choices" ):
93+ if isinstance (c , dict ) and c .get ("value" ):
94+ choices .append ((c ["value" ].strip (), c ["value" ].strip ()))
95+ else :
96+ choices .append ((c .strip (), c .strip ()))
8497 options .update ({"choices" : choices })
8598 return options
8699
@@ -105,7 +118,12 @@ class RadioField(BaseField):
105118
106119 def get_options (self , block_value ):
107120 options = super ().get_options (block_value )
108- choices = [(c .strip (), c .strip ()) for c in block_value .get ("choices" )]
121+ choices : List [Tuple [str , str ]] = []
122+ for c in block_value .get ("choices" ):
123+ if isinstance (c , dict ) and c .get ("value" ):
124+ choices .append ((c ["value" ].strip (), c ["value" ].strip ()))
125+ else :
126+ choices .append ((c .strip (), c .strip ()))
109127 options .update ({"choices" : choices })
110128 return options
111129
@@ -130,7 +148,12 @@ class CheckboxesField(BaseField):
130148
131149 def get_options (self , block_value ):
132150 options = super ().get_options (block_value )
133- choices = [(c .strip (), c .strip ()) for c in block_value .get ("choices" )]
151+ choices : List [Tuple [str , str ]] = []
152+ for c in block_value .get ("choices" ):
153+ if isinstance (c , dict ) and c .get ("value" ):
154+ choices .append ((c ["value" ].strip (), c ["value" ].strip ()))
155+ else :
156+ choices .append ((c .strip (), c .strip ()))
134157 options .update ({"choices" : choices })
135158 return options
136159
0 commit comments