Vic
Vic

Reputation: 177

How to call individual form fields in Django templates that have the same name?

This is how I would call a individual form field:

{{ form.product }}

This would display only the form element with the name "product". But what about in the case of radio buttons or checkboxes where multiple form fields have the same name. How do I call one over another then?

Is there a way to use value instead of name or some other distinguishing id?

P.S. please don't post any python code suggestions. I am a front end developer and have access to only template tags, filters and variables.

Upvotes: 0

Views: 630

Answers (1)

Bartek
Bartek

Reputation: 15599

I think you need to work more closely with your Python developers :-)

Basically, if the case were to arise where there are multiple radio buttons/checkboxes with the same name, they should be easily provided to you under the form, using the same schema you're using already.

So, make sure your developer gives you access to all the form elements you need. If they're creating a widget that spits out 4 different radio buttons, you should be able to call them using the way you've done it already, form.some_radio_buttons

Nothing special, just a matter of the backend developer giving you the right information.

Upvotes: 1

Related Questions