How to disable resize textarea in django?
I'm trying to disable resize to the textarea widget in django, this is my form:
class VForm(forms.ModelForm):
class Meta:
model = Visions
widgets = {'vision': forms.Textarea(attrs={'rows':6,
'cols':22,
'resize':'none'}),
}
Adding the resize property to none isn't working
最简单的方法是添加一个样式属性:
widgets = {'vision': forms.Textarea(attrs={'rows':6,
'cols':22,
'style':'resize:none;'}),
}
Something like this in your CSS:
.no-resize {
resize: none;
}
And this in your Python to add the class:
class VForm(forms.ModelForm):
class Meta:
model = Visions
def __init__(self, *args, **kwargs):
"""
This has been overridden to customise the textarea form widget.
"""
super(VForm, self).__init__(*args, **kwargs)
self.fields['vision'].widget.attrs['class'] = 'no-resize'
我认为更好的方式是使用style
而不是class
:
class VForm(forms.ModelForm):
class Meta:
model = Visions
def __init__(self, *args, **kwargs):
super(VForm, self).__init__(*args, **kwargs)
self.fields['vision'].widget.attrs['style'] = 'resize:none'
链接地址: http://www.djcxy.com/p/27396.html
上一篇: 在textarea上禁用滚动