0

我有一个像这样的表格:

.row-fluid
  = form_for(@client) do |f|
    - if @client.errors.any?
      #error_explanation
        %h2
          = pluralize(@client.errors.count, "error")
          prohibited this client from being saved:
        %ul
          - @client.errors.full_messages.each do |msg|
            %li= msg
    .fieldset
      %legend
        = @header
      .control-group
        %label.control-label
          Name
        .controls
          = f.text_field :name, :class => "input-xlarge"
      .control-group
        %label.control-label
          Street Address
        .controls
          = f.text_field :street, :class => "input-xlarge"
      .control-group
        %label.control-label
          Unit
        .controls
          = f.text_field :unit, :class => "input-small", :placeholder => "optional"
      .control-group
        %label.control-label
          City
        .controls
          = f.text_field :city, :class => "input-xlarge"
      .control-group
        %label.control-label
          State
        .controls
          = f.text_field :state, :class => "input-small"
      .control-group
        %label.control-label
          Zip
        .controls
          = f.text_field :zip, :class => "input-small"
    .form-actions
      = f.submit "Save", :class => "btn btn-primary"
      .btn
        = link_to "Cancel", :root, :style => "color: #333; text-decoration: none;"

我有一个模式,我正在加载里面的表单,如下所示:

  .span2.offset2
    %a.btn{"data-toggle" => "modal", :href => "#myModal", :role => "button"} New Client
    / Modal
    #myModal.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
      .modal-header
        %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
        %h3#myModalLabel Modal header
      .modal-body
        %p
          = render "form"
      .modal-footer
        %button.btn{"aria-hidden" => "true", "data-dismiss" => "modal"} Close
        %button.btn.btn-primary Save changes

我想知道如何让 Save Changes 按钮提交表单。我需要添加 javascript 才能让它工作吗?

4

1 回答 1

0

您需要确保输入和按钮属于一个form元素。使用您当前的标记可能很难实现这一点。

或者,您可以使用 JavaScript 提交表单,但第一种方法要好得多,因为您可以免费获得很多功能。

于 2013-03-30T04:51:07.950 回答