donkeyboy72
donkeyboy72

Reputation: 1943

Django displaying CharField as TextField in forms error

I'm trying to make a a field called text which is a CharField work like an textfield because I can't use textfield in forms so What I did was I enlarged the charfield using CSS . The problem is , when I type a sentence . The sentence is display not from top to bottom like textfield but in the middle of box like a straight line. How do I make this Charfield work extactly like textfield

enter image description here models.py

class House(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField(max_length=100)
    description = models.Textfield(max_length=100)

My forms.py

class HouseForm(forms.ModelForm):
    text = forms.CharField(required=False, )

    class Meta:
         model = House
         fields = ('name', 'description',)

my views.py

def House(request):
     form = houseForm()
     return render(request,'house.html',{'form':form})

template

<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{form.name}}
{{form.text}}
{{form.description}}
<input type = "submit" value="save" id="box2"/>
</form>

My CSS

#id_text {
    width: 230px;
    height: 80px;
    color:#9B5A3C;
    font-family: Arial;
    font-size: 15px;
    position:absolute;
    left:700px;
    top: 260px;
}

Upvotes: 2

Views: 2914

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47172

For your use case use a TextArea widget

text = forms.CharField(widget=forms.Textarea)

if you wanna specify some attributes for the widget you can do this in your form which think is pretty nice.

class HouseForm(forms.ModelForm):
    class Meta:
        model = House
        widgets = {
            'text': forms.Textarea(attrs={'rows':5, 'cols':10}), #this is changeble.
        }

Here's the documentation

Upvotes: 6

Related Questions