I am trying to implement the common use case of a form with an "I agree
to these terms" checkbox.
I'm not that interested in having that field in my model, so I create
my own Manipulator, define the fields I want in the form (with the
checkbox), then do validation against that Manipulator.
If that works out okay, I convert from the custom Manipulator to the
various Models where data will be stored (violating DRY here, I know,
but it seemed like good solution).

The problem I have is with simply validating that the checkbox is
checked.
I represent it as a forms.CheckboxField, with a custom validator
function, but this only seems to run when the checkbox is checked on
the form.
This makes sense considering how forms only exist in the POST data when
they are active, but I still want to handle this sanely within a
manipulator, so I can return the usual FormWrapper object to the
template.

I trid the "magic name" validate_<field_name> pattern, didn't seem to
work, and searched the newsgroups for some answers, but nothing
concrete came up.
I may be ignoring the obvious here, but it would be most kind of anyone
to point it out to me.

On an ending note, I would just say that I very much enjoy Django,
although documentation could be better (especially on "advanced" forms)

Here comes a paste of my Manipulator (formatting might be eaten by
processing),
the point is I would like to run the validator even if the checkbox is
not checked (or another solution with same result).
-----------------------------------------------------------------------------------------------------------------------
class CreateAccountManipulator(forms.Manipulator):
    def __init__(self):
        self.fields = (

forms.TextField(field_name="fornavn",maxlength=100,is_required=True),

forms.TextField(field_name="etternavn",maxlength=100,is_required=True),
            forms.TextField(field_name="firma",maxlength=100),

forms.TextField(field_name="adresse",maxlength=100,is_required=True),
            forms.IntegerField(field_name="postnr",is_required=True),

forms.TextField(field_name="poststed",is_required=True,maxlength=100),
            forms.IntegerField(field_name="mobilnr",is_required=True),
            forms.EmailField(field_name="epost",is_required=True),

forms.SelectField(field_name="select",choices=PAYMENT_PLANS),

forms.SelectField(field_name="invoicetype",choices=PAY_METHOD),

forms.CheckboxField(field_name="conditions_approve",validator_list=[self.validate_conditions_approve])
        )

    def validate_conditions_approve(self, data, form):
       if not data == "on": #See note
            raise validators.ValidationError("Checkbox must be
checked")

note: Is this a way of checking for checked ? see
forms.CheckboxField.html2python


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to