简体   繁体   中英

Create simple_form in bootstrap modal with haml

I'm trying to use simple_form in a Bootstrap 3 modal in Ruby 2.5 on Rails (v5.1) with haml in the view.

I want to be able to put the submit button in the modal footer, but this breaks the haml conventions. Any workarounds?

Modal

#addDataModelModal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "exampleModalLabel", role: "dialog", tabindex: "-1"}
  .modal-dialog{role: "document"}
    .modal-content
      .modal-header
        %h5#addDataModelModalLabel.modal-title Choose a Data Model
        %button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
          %span{"aria-hidden" => "true"} ×
      .modal-body
        .text-center
          = simple_form_for @project, :url => add_project_datastores_project_path, :method => 'post' do |f|
            = f.input :project_datastores, collection: @datastores, label_method: :name, value_method: :datastore_sid, prompt: "Select a Data Model"
            = f.submit 'Add Data Model', :class => 'pull-right btn btn-primary'
      .modal-footer
        %button.btn.btn-secondary{"data-dismiss" => "modal", type: "button"} Close
        .text-center

start the = simple_form_for right below the .modal-content div so you can insert your f variable into all its children divs.

#addDataModelModal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "exampleModalLabel", role: "dialog", tabindex: "-1"}
  .modal-dialog{role: "document"}
    .modal-content
      = simple_form_for @project, :url => add_project_datastores_project_path, :method => 'post' do |f|
        .modal-header
          %h5#addDataModelModalLabel.modal-title Choose a Data Model
          %button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
            %span{"aria-hidden" => "true"} ×
        .modal-body
          .text-center
            = f.input :project_datastores, collection: @datastores, label_method: :name, value_method: :datastore_sid, prompt: "Select a Data Model"
        .modal-footer
          %button.btn.btn-secondary{"data-dismiss" => "modal", type: "button"} Close
          .text-center
            = f.submit 'Add Data Model', :class => 'pull-right btn btn-primary'

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