我正在尝试禁用调整大小到django中的textarea小部件,这是我的表单:
class VForm(forms.ModelForm):
class Meta:
model = Visions
widgets = {'vision': forms.Textarea(attrs={'rows':6,
'cols':22,
'resize':'none'}),
}
将resize属性添加到none无法正常工作
答案 0 :(得分:9)
最简单的方法是添加样式属性:
widgets = {'vision': forms.Textarea(attrs={'rows':6,
'cols':22,
'style':'resize:none;'}),
}
答案 1 :(得分:2)
你的CSS中有这样的东西:
.no-resize {
resize: none;
}
这在你的Python中添加了类:
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'
答案 2 :(得分:1)
我认为更好的方法是使用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'