@@ -23,16 +23,18 @@ class NonStrictSelect(Select):
2323 A Select widget for non-strict EnumChoiceFields that includes any existing
2424 non-conforming value as a choice option.
2525 """
26+
2627 choices : Iterable [Tuple [Any , str ]]
2728
2829 def render (self , * args , ** kwargs ):
2930 """
3031 Before rendering if we're a non-strict field and our value is not
3132 one of our choices, we add it as an option.
3233 """
34+
3335 value : Any = getattr (kwargs .get ('value' ), 'value' , kwargs .get ('value' ))
3436 if (
35- value not in self . attrs . get ( ' empty_values' , [])
37+ value not in EnumChoiceField . empty_values
3638 and value not in (
3739 choice [0 ] for choice in self .choices
3840 )
@@ -120,6 +122,7 @@ def _coerce(self, value: Any) -> Union[Choices, Any]:
120122 non-strict field and the value is of a matching primitive type
121123 :raises ValidationError if a valid return value cannot be determined.
122124 """
125+
123126 if value in self .empty_values :
124127 return self .empty_value
125128 if self .enum is not None and not isinstance (value , self .enum ):
@@ -141,12 +144,6 @@ def _coerce(self, value: Any) -> Union[Choices, Any]:
141144 ) from err
142145 return value
143146
144- def widget_attrs (self , widget : Widget ) -> Dict [Any , Any ]:
145- attrs = super ().widget_attrs (widget )
146- attrs .setdefault ('empty_value' , self .empty_value )
147- attrs .setdefault ('empty_values' , self .empty_values )
148- return attrs
149-
150147 def prepare_value (self , value : Any ) -> Any :
151148 """Must return the raw enumeration value type"""
152149 value = self ._coerce (value )
0 commit comments