0

I need something like this:

<div>
<input type="text"></input>
<input type="hidden" name="attr1" value="true">
<input type="hidden" name="attr2" value="true">
<input type="hidden" name="attr3" value="false">
</div>
<div>
<input type="text"></input>
<input type="hidden" name="attr11" value="true">
<input type="hidden" name="attr22" value="true">
<input type="hidden" name="attr33" value="true">
</div>

I need to attach some extra non-standard attributes to each field. What is the best way to do this? How to realize above example? I can do this with custom template in django but it is unnecessary client-server communication.

0

1 Answer 1

2

You can set any attributes you want in the form. For example you can set rows and cols attributes like this:

class MyForm(forms.Form):
    description = forms.Textarea(attrs={'my_attr': 'and_value'})

The rendered result is:

<textarea my_attr="and_value" name="description" id="id_description"></textarea>
Sign up to request clarification or add additional context in comments.

2 Comments

Ok that. But i need to attach non standard attrs. Like myrows not rows
You can add any kind of attributes this way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.