And so? I don't get you. How can i requere that the user will select a checkbox OR input some text in TextInput?
2009/5/19 Thierry <lamthie...@gmail.com> > Isn't required the default behaviour of Field: > > http://docs.djangoproject.com/en/dev/ref/forms/fields/ > > From the above code, TextInput is required: > > forms.TextInput(), > > > On May 18, 1:15 pm, "[CPR]-AL.exe" <cpr.al....@gmail.com> wrote: > > class CheckboxSelectWithTextInputWidget(forms.MultiWidget): > > > > def __init__(self,choices, attrs=None): > > > > widgets = ( > > forms.CheckboxSelectMultiple(choices = choices), > > forms.TextInput(), > > ) > > super(CheckboxSelectWithTextInputWidget,self).__init__ > > (widgets,attrs) > > > > def decompress(self,value): > > print "widget value in decompress for checkbox-with-textinput: > > %s" % str(value) > > if value: > > return value.split(',') > > return [None,None] > > > > def format_output(self, rendered_widgets): > > > > rendered_widgets[0] = u"выберите: " + rendered_widgets[0] > > rendered_widgets[1] = u"и (или) впишите свои значения через > > запятую: " + rendered_widgets[1] > > > > return u''.join(rendered_widgets) > > > > class CheckboxSelectWithTextInput(forms.MultiValueField): > > > > widget = CheckboxSelectWithTextInputWidget > > > > def __init__(self, choices, *args, **kwargs): > > print 'CheckboxSelectWithTextInput initialised' > > self.choices = choices > > > > widgets = CheckboxSelectWithTextInputWidget(choices) > > fields=(forms.MultipleChoiceField(choices = self.choices, > > label = u"выберите", required = False), forms.CharField(label = > > u"впишите свои значения", required = False)) > > super(CheckboxSelectWithTextInput, self).__init__(fields, > > widget=widgets, *args, **kwargs) > > > > def compress(self, data_list): > > print "data list for from-to-range: %s" % data_list > > try: > > result = data_list[0] #добавим в вывод значения из > > чекбоксов > > > > #заберем из поля ввода и разделим запятыми введенные > > дополнительные варианты: > > additional_result = data_list[1].split(",") > > > > #порежем лишние пробелы и пустые значения и добавим к > > результирующему массиву элементы из текстового поля: > > for word in additional_result: > > if word.strip(): > > result.append(word.strip()) > > > > except IndexError: > > result = u"" > > > > return result > > > -- Sincerely yours, Alexey. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---