2008-08-08

MultipleSubmitButton Widget for ChoiceField

Recently I published a snippet with a widget rendering a choice field as a series of submit buttons.

So the {{ form.do }} field from the following form:

SUBMIT_CHOICES = (
('save', _("Save")),
('save-add', _("Save and Add Another")),
)

class TestForm(forms.Form):
do = forms.ChoiceField(
widget=MultipleSubmitButton,
choices=SUBMIT_CHOICES,
)



will be rendered as:

<ul>
<li><button type="submit" name="do" value="save">Save</button></li>
<li><button type="submit" name="do" value="save-add">Save and Add Another</button></li>
</ul>


Can somebody enhance this widget so that it supports iteration through different choices and getting specific buttons by indexes in the template? My trials failed, but maybe you will succeed!

2 comments:

  1. Arrrgh! ****ing IE submits the inner HTML of the button instead of its value. Any ideas?

    ReplyDelete
  2. Uff.. Fixed the case of IE by overriding the value_from_dict method.

    ReplyDelete