简体   繁体   中英

Textarea sizing issue with Bootstrap-Sass and Formtastic

Problem: I am not sure why my input text box has fixed width(too small so it does not fit the screen), and I cannot change the size with proper ways. Could anyone help me find what's causing this?

In my form partial:

<%= semantic_form_for @post do |f| %>
<%= f.inputs do %>
    <%= f.input :name, :input_html => { :size => 10000 } %>
    <%= f.input :content, :input_html => {:size => 100000 } %>
<% end %>
<%= f.actions do %>
    <%= f.action :submit, :as => :button %>
    <%= f.action :cancel, :as => :link %>
<% end %>
<% end %>

在此处输入图片说明

Update: I found out that

<%= f.input :name, :input_html => { :style => "width: 80%" } %>

successfully changes the size of the textarea.

New Question: How come

<%= f.input :content, :input_html => {:size => 100000 } %>

fails to work?

To add one more question.. When the user is logged in, I want to simply pass his name for the :name symbol. So I wanted to set the input type as hidden on condition, but I'm not sure how the formtastic syntax works in this case... I tried:

<%= f.input :name, :as => hidden, :name => <%= current_user.name %> %>

And I also tried simply getting rid of the input area for the name variable, and set

<% @post.name = current_user.name %>

But the problem with this is, this way does not pass the validation check that requires the name input to be present.

These two attempts both failed. Is there anyone who can give me answers for 1)textbox sizing issue and 2)getting the input issue?

After more research, I found solutions for both problems. However for the first problem, it's just a workaround and I'm still not sure why I cant edit the width of text boxes, but only the height.

Solution for the first problem:

<%= f.input :content, :input_html => {:class => 'span10' } %>

Solution for the second problem:

<%= f.input :name, :input_html => {:value => @post.name } %>

For the first problem, I think formtastic automatically sets the max-width of a form as 72% according to this , which causes :cols => somesize not to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM