Tuesday, May 1, 2012

Access specific ModelForm field option within array of ModelForms for use with .js

Hello, 

I have the following situation:

I am rendering an array of ModelForms to my template. ie. formArray = [<ModelForm1>, <ModelForm2>, <ModelForm3>]

In the template I display the forms with the following:

{% for form in formArray %}
<div class="clearfix">
{{ form }}
</div>
{% endfor %}

Previously I have accessed certain ModelForms using {% if forloop.counter == # %} to add some customization.

However, now I would like more detailed control of certain field tags within a given ModelForm. ie. ModelForm2 is a RadioSelect, and I would like to add an onChange="some function" to one of the Radio Buttons within this ModelForm. 

Is there a way to access this specific field in my implementation directly? Or, through the use of a custom template filter?

To give the larger picture my goal is to have an "Other" RadioButton that when selected shows a Other text input using javascript, but while using ModelForms.

As such, if there is an entirely different way to going about this I would love to hear it. 

Any help would be greatly appreciated!


JD



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/OVPO5oqiXc4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment