如何禁用django中的调整textarea大小?

我试图禁用django中textarea小部件的大小,这是我的形式:

class VForm(forms.ModelForm):
    class Meta:
        model = Visions
        widgets = {'vision': forms.Textarea(attrs={'rows':6,
                                                   'cols':22,
                                                   'resize':'none'}),
        }

将resize属性添加到none不起作用


最简单的方法是添加一个样式属性:

 widgets = {'vision': forms.Textarea(attrs={'rows':6,
                                            'cols':22,
                                            'style':'resize:none;'}),
    }

在你的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'

我认为更好的方式是使用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/27395.html

上一篇: How to disable resize textarea in django?

下一篇: Telerik Kendo MVC TextBox Multiline Mode