Wednesday 15 May 2013

Django Form Processing With Custom Widget -



Django Form Processing With Custom Widget -

i implementing star rating system, , having problem getting form validate. using custom widget (see code below), , plugin http://plugins.krajee.com/star-rating. when rating selected, setting value on input value of rating. want value on input value cleaned , validated form, right form prompts rating required field. how django form take value of input on custom widget value validate?

class starratingswidget(forms.widget): def render(self, name, value, attrs=none): homecoming mark_safe('<input id="id_star_rating" type="number" class="rating" min=0 max=5 step=0.5 data-size="xs" data-glyphicon="false" data-show-caption="false" >')

turns out needed provide right name widget, per django form standards, , implement value_from_datadict method homecoming value of widget.

class starratingswidget(forms.widget): def render(self, name, value, attrs=none): homecoming mark_safe('<input name="%s" id="id_rating" type="number" class="rating" value=0 min=0 max=5 step=0.5 data-size="xs" data-glyphicon="false" data-show-caption="false" >' % name) def value_from_datadict(self, data, files, name): homecoming float(data[name])

django django-forms

No comments:

Post a Comment