简体   繁体   English

Bootstrap-Sass 和 Formtastic 的 Textarea 大小问题

[英]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.成功更改了 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.再添加一个问题..当用户登录时,我想简单地将他的名字传递给 :name 符号。 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:所以我想在条件下将输入类型设置为隐藏,但我不确定在这种情况下 formtastic 语法是如何工作的......我试过:

<%= 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而且我还尝试简单地去掉 name 变量的输入区域,然后设置

<% @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?有没有人可以为我解答1)文本框大小问题和 2)输入问题?

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.对于第一个问题,我认为 formtastic 会根据this自动将表单的最大宽度设置为 72%,这会导致 :cols => somesize 不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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