0

I would like to make certain fields in the form to read only while other editable. I read this in HTML (Read only)

<form action="demo_form.asp">
Country: <input type="text" name="country" value="Norway" readonly="readonly" /><br />
<input type="submit" value="Submit" />
</form>

This example specifically states the fields which will be editable. But i am using Django Forms. I am not able to do this specifically because the field is derived from models.py.

What options do i have in making the fields read only? Need some suggestions and guidance...

2 Answers 2

3

When creating the form add an extra param to add the readonly attribute, for your field:

name = forms.CharField(widget=forms.TextInput(attrs={'readonly':'readonly'}))
Sign up to request clarification or add additional context in comments.

Comments

1

You can use jQuery to add the property?

$('.inputClass').prop("readonly", true);

2 Comments

"usually" you'd want to use .prop() - answer reworded to reflect that
i am curious to know whether u can use css to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.