On Wed, 2011-04-06 at 12:51 -0700, Mike Ramirez wrote:

> the form widgets accept a key word arguement of "attrs"[1] which takes a 
> dictionary that has the key as the option and the value is the options fale. 
> i.e.: attrs={'readonly': 'true'}. These are added to the field when it's 
> rendered to html. 

Thanks.  I had just discovered that when I read your mail.  Good to know
I was on the right track!  I ended up with two forms, and use the
appropriate one in each view.

class ItemForm(forms.Form):
    url = forms.URLField()
    title = forms.CharField()
    text = forms.CharField(required=False)

class ReadOnlyItemForm(forms.Form):
    ro_text_widget = forms.TextInput(attrs={'disabled': 'disabled'})
    url = forms.URLField(widget=ro_text_widget)
    title = forms.CharField(widget=ro_text_widget)
    text = forms.CharField(widget=ro_text_widget, required=False)



Minor nit: of these three only the second and third are valid HTML.

<input readonly="True">
<input readonly="readonly">
<input readonly>

It's been a long time since I've started a web project from ground zero.
I've decided to take advantage of that and be fanatical about all HTML
validating.  We'll see how long that lasts :-)

-- 
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.

Reply via email to