The validation is easy. Override the form's clean() method to do any
validation which needs to check the value of more than one field. For
example, if you want a text box to be required sometimes, define it as
not required in the form, then check the boolean in clean() and raise a
forms.ValidationError if appropriate.
If you want to change which widget is being used and where it's
displayed based on the checkbox then you'd have to use AJAX to make that
work "live" anyway. Or maybe have two form fields, one of each type, and
dynamically hide one and show the other when the checkbox is changed.
You could also use your form's clean() override to assign the correct
value to your form field.
Example:
Say you have a field named named 'reason,' and you want to make it
a select box with hard-coded choices if a boolean for is True, but a
free-form text field if it's False.
If you have fields named reason_select and reason_text, you could
use JavaScript to select the appropriate one to show based on the checkbox.
Then, in form.clean(), you use the value of the checkbox to
determine whether to fill self.cleaned_data['reason'] with the value
from self.cleaned_data['reason_select'] or self.cleaned_data['reason_text'].
I hope this helps. I think we're zeroing in on your solution.
--
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.