i struggling requirement now, want add image choice field label , dont have clue how it. using django form wizard render form. here image shows want achieve : 
and here have got right ( make radio buttons inline, know achieved through css): 
here forms.py:
from django import forms django.utils.translation import gettext _ choices=[('0','pay card'), ('1','invoice')] class paymentform(forms.form): title = 'payment' payment_method = forms.choicefield(label = _("payment options"), choices=choices, widget=forms.radioselect(), required = true) i rendering using wizard form:
{{ wizard.form.payment_method.label_tag }} {{ wizard.form.payment_method|safe }} {{ wizard.form.payment.errors}} anyone has suggestion apart custom widget?
1) shortly (but i'm not sure) call function 'pay card' , return <img>... need.
2) can make somthing @gahbu said
3)long [better, think, untested :( ]: make renderer:
from myapp.my_widgets import cardsradiofieldrenderer card_choice = '0' choices=[(card_choice,'pay card'), ('1','invoice')] class paymentform(forms.form): title = 'payment' payment_method = forms.choicefield(label = _("payment options"), choices=choices,widget=forms.radioselect(renderer=cardsradiofieldrenderer), required = true) # myapp/my_widgets.py class cardradioinput(radioinput): def __init__(self, name, value, attrs, choice, index): self.name, self.value = name, value self.attrs = attrs choice_value = force_text(choice[0]) self.choice_value = choice_value if choice_value == card_choice: choice_label = force_text(self.get_html_for_card_choice()) else: choice_label = force_text(choice[1]) self.choice_label = choice_label self.index = index def get_html_for_card_choice(self): #some logic images tags (<img ...> <img ...>) return text class cardsradiofieldrenderer(radiofieldrenderer): def __getitem__(self, idx): choice = self.choices[idx] # let indexerror propogate return cardradioinput(self.name, self.value, self.attrs.copy(), choice, idx)
Comments
Post a Comment