17👍
✅
The simplest way to do this is to add a style attribute:
widgets = {'vision': forms.Textarea(attrs={'rows':6,
'cols':22,
'style':'resize:none;'}),
}
2👍
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'
👤Matt
- How can i access the model instance used by a form from a template?
- How can i customize the html output of a widget in Django?
- Dict keys with spaces in Django templates
- How do I set default field value to value of other field in a Django model?
- Django Rest Framework bulk updates inserting instead of updating
1👍
I think the better way is using style
instead of 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'
Source:stackexchange.com