n0rd
n0rd

Reputation: 12670

How to remove size property from input generated by text_field?

I have an .erb file with form template that uses form_for helper to generate form, and some of their fields generated with text_field method. In resulting HTML I see size properties are added to every input generated with aforementioned method.

I want to control input sizes with CSS and that size property prevents me from doing it. Is there any way to tell text_field method that I don't want them?

I tried to pass :size => nil as option to that method, but that didn't help.

Upvotes: 7

Views: 1639

Answers (3)

przbadu
przbadu

Reputation: 6049

<%= f.text_field :name, :size => nil, :style => "width: 120px; height: 20px;" %>. This will work

Upvotes: 0

iJK
iJK

Reputation: 4775

This worked for me

<%= f.text_field :title, :size => nil %>

Upvotes: 8

danengle
danengle

Reputation: 566

You can use CSS or the :size option to control the size of input fields. I'm not sure if there is an option to remove the size attribute, I've always just ignored it and set the width of input fields with CSS.

Upvotes: 2

Related Questions