使用Rails 4.1.6,simple_form 3.1.0.rc2,Bootstrap 3 我想在simple_form中设置一个按钮来打开Bootsrap模式窗口来执行js用户选择
我的简单表格如下:
.form-inputs
.row
.col-sm-8.col-md-8.col-lg-8
- if ((current_user.has_role? :superadmin) || (current_user.has_role? :media_admin))
.form-group
%button.btn.btn-default{:'data-toggle' => "modal" , :'data-target' => "#myModal"}
Select Owner of album
= f.input :user_id, as: :hidden, input_html: {value: current_user.id}
.row
.col-sm-8.col-md-8.col-lg-8
= f.input :title, :label => t(:title, scope: :album).capitalize
= f.input :description, as: :text, :label => t(:description, scope: :album).capitalize
我添加了一个标准的bootstrap模态测试
#myModal.modal.fade{ tabindex: "-1" ,role: "dialog", :'aria-labelledby' => "myModalLabel", :'aria-hidden' => "true"}
.modal-dialog
.modal-content
.modal-header
%button.close{type: "button", :'data-dismiss' => "modal" }
%span{:'aria-hidden' => true}
×
%span.sr-only
Close
%h4#myModalLabel.modal-title
Modal Title
.modal-body
= "Modal body"
.modal-footer
%button.btn.btn-default{type: "button", :'data-dismiss' => "modal" }
Close
%button.btn.btn-primary{type: "button", :'data-dismiss' => "modal" }
Save changes
当我点击“选择相册所有者”按钮时,它将作为提交者并尝试保存表单数据....不会打开模式表单
我错过了什么吗?
答案 0 :(得分:1)
我宁愿使用带有按钮类的链接标记....
.form-group
%a.btn.btn-success{href: "#", :'data-toggle' => "modal" , :'data-target' => "#myModal"}
Select Owner of album