python - Render Input & Label tags at the same DOM level with Django ChoiceInput -
the default django choiceinput outputs <input>
within <label>
tag & i've been asked output them @ same level in dom have written custom renderer.
the field isn't rendering safe html in browser i'm seeing field label, raw html choices.
i've looked on choicefieldrenderer
i'm inheriting & it's render function returns mark_safe()
string, why field render raw html?
my form field declared so;
class signupform(forms.modelform): my_field = forms.nullbooleanfield( widget=forms.widgets.radioselect( choices=field_choices, renderer=myradiofieldrenderer ), required=true, initial=true )
and custom renderer;
class mychoiceinput(forms.widgets.choiceinput): def render(self, name=none, value=none, attrs=none, choices=()): if self.id_for_label: label_for = format_html(' for="{0}"', self.id_for_label) else: label_for = '' return format_html( '{0}<label{1}>{2}</label>', self.tag(), label_for, self.choice_label ) class radiochoiceinput(mychoiceinput): input_type = 'radio' def __init__(self, *args, **kwargs): super(radiochoiceinput, self).__init__(*args, **kwargs) self.value = force_text(self.value) class myradiofieldrenderer(forms.widgets.choicefieldrenderer): choice_input_class = radiochoiceinput
Comments
Post a Comment