[英]Rails form input fields overflowing with Bootstrap 3 modal dialog
I am using the simple_form
gem to make a form in a modal dialog.我正在使用simple_form
gem 在模式对话框中创建一个表单。 The issue is that the input fields go over the edge of the modal.问题是输入字段超出了模态的边缘。
The code cascades as follows: index.html.erb
代码级联如下: index.html.erb
<div class="row">
<div class="cold-md-2">
<%= link_to "New Author", new_author_path, remote: true, class: "btn btn-primary"%>
</div>
<div id="author-modal" class="modal fade" role="dialog"></div>
</div>
new.js.erb
$('#author-modal').html('<%= escape_javascript(render 'new') %>');
$('#author-modal').modal('show');
_new.html.erb
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h4 class="modal-title" id="myModalLabel">Add New Author</h4>
<%= render 'form'%>
</div>
</div>
</div>
and lastly _form.html.erb
最后是_form.html.erb
<%= simple_form_for @author, remote: true, html: { class: "form-horizontal" } do |f|%>
<div class="modal-body">
<ul class="errors"></ul>
<div class="form-group">
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :title %>
</div>
</div>
<div class="modal-footer">
<%= f.button :submit, class: "btn btn-primary" %>
<%= link_to "Cancel", "#", class: "btn", data: {dismiss: "modal"}%>
</div>
<% end %>
why isn't the bootstrap default 100% width for form items limited to the modal?为什么表单项的引导默认 100% 宽度不限于模态?
Update the view as below,更新视图如下,
<div class="form-group">
<%= f.input :first_name, input_html: { class: "form-control" } %>
<%= f.input :last_name, input_html: { class: "form-control" } %>
<%= f.input :title, input_html: { class: "form-control" } %>
</div>
For width: 100%
, you should use form-control
class for the input controls.对于width: 100%
,您应该使用form-control
类作为输入控件。
Refer to Forms Basic Example请参阅表单基本示例
Individual form controls automatically receive some global styling.单个表单控件会自动接收一些全局样式。 All textual
<input>, <textarea>, and <select>
elements with .form-control are set to width: 100%;所有带有 .form-control 的文本<input>, <textarea>, and <select>
元素都设置为 width: 100%; by default.默认情况下。
I overwrode the bootstrap_config.css.scss with:我用以下内容覆盖了 bootstrap_config.css.scss:
input{ width:100%;}
and it solves it. input{ width:100%;}
它解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.