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
A simple way to ensure that the control is not resizable is to add an explicit style="resize: none;" attribute on the textarea element using the HTML Form Element Attributes property.
In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.
To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.
The simplest way to do this is to add a style attribute:
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With