rails jquery禁用下载按钮,直到保存表单

时间:2016-08-01 14:43:13

标签: javascript jquery twitter-bootstrap

查看

我创建了一个具有保存和下载按钮的表单。我希望在完成所有字段之前禁用保存按钮,并在保存表单之前禁用下载按钮。



- content_for :javascript_includes do
  = javascript_include_tag "dropdown.js", "business.js", "bootstrap-toggle.min.js"
.col-sm-12
  .main-login.main-center.customer_details
= nested_form_for(@customer_detail) do |f|
  - all_views_side_error_messages!(@customer_detail)
  .form-alignment
    .fieldset
      .row
        .col-sm-12
        = f.label :customer_name,"Organisation/Customer Name", class: "col-sm-3 control-label text-right"
        = f.text_field :customer_name, autofocus: true, class: "col-sm-3"
        = f.label :residential_type,"Residential Type", class: "col-sm-3 control-label text-right"
        = f.check_box :residential_type, autofocus: true, "data-width" => "200", class: "toggle-two-resident select-resident col-sm-3"
    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :customer_id,"Customer ID", class: "col-sm-3 control-label text-right"
        = f.text_field :customer_id, autofocus: true, class: "col-sm-3"
        = f.label :attention_to,"Attention To", class: "col-sm-3 control-label text-right"
        = f.text_field :attention_to, autofocus: true, class: "col-sm-3"
    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :address,"Address", class: "col-sm-3 control-label text-right"
        = f.text_area :address, autofocus: true, class: "col-sm-3"
        = f.label :city,"City", class: "col-sm-3 control-label text-right"
        = f.text_field :city, autofocus: true, class: "col-sm-3"
    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :pin_code,"Pin Code", class: "col-sm-3 control-label text-right"
        = f.text_field :pin_code, autofocus: true, class: "col-sm-3"
        %div{id: 'state_field'}
          = f.label :state,"State", class: "col-sm-3 control-label text-right"
          = f.select(:state, options_for_select(State.collect_state),{},{class: "selectpicker col-sm-3 column-width-change", prompt: "Select State", "data-live-search": "true"})
        %div.hide{id: 'country_field'}
          = f.label :country,"Country", class: "col-sm-3 control-label text-right"
          = f.select(:country, CountryList.collect_country_list,{}, {class: "selectpicker add_class_country dropdown_country col-sm-3 column-width-change", title: "select country", "data-live-search": "true"})

    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :email,"Email", class: "col-sm-3 control-label text-right"
        = f.email_field :email, autofocus: true, class: "col-sm-3"
        = f.label :contact_no,"Contact No", class: "col-sm-3 control-label text-right"
        = f.text_field :contact_no, autofocus: true, class: "col-sm-3"
    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :website,"Website", class: "col-sm-3 control-label text-right"
        = f.text_field :website, autofocus: true, class: "col-sm-3"
        %div.hide{id: 'currency_field'}
          = f.label :currency_type,"Currency Type", class: "col-sm-3 control-label text-right"
          = f.select(:currency_type, CurrencyType.collect_currency_type,{},{class: "selectpicker dropdown_business column-width-change", prompt: 'Select', "data-live-search": "true"})
        %div{id: 'change_resident'}
          = f.label :business_type,"Business Type", class: "col-sm-3 control-label text-right"
          = f.select(:business_type, BusinessType.collect_business_type,{},{class: "selectpicker dropdown_business column-width-change", prompt: 'Select', "data-live-search": "true"})
          %br
          %br

    .fieldset
      .row
        .col-sm-12
        = f.label :service_tax_reg_no,"Service tax Registration No", class: "col-sm-3 control-label text-right"
        = f.text_field :service_tax_reg_no, autofocus: true, class: "col-sm-3"
        = f.label :pan_no,"PAN No", class: "col-sm-3 control-label text-right"
        = f.text_field :pan_no, autofocus: true, class: "col-sm-3"
    %br

    .fieldset
      .row
        .col-sm-12
        = f.label :local_sales_tax_reg_no,"Local Sales Tax Registration No", class: "col-sm-3 control-label text-right"
        = f.text_field :local_sales_tax_reg_no, autofocus: true, class: "col-sm-3"
        = f.label :central_sales_tax_no,"Central Sales Tax Registration No", class: "col-sm-3 control-label text-right"
        = f.text_field :central_sales_tax_no, autofocus: true, class: "col-sm-3"
    %br

    = render partial: 'customer_details/goods_address', locals: {customer_detail: @customer_detail}
    %br

    .fieldset
      .row
        .col-sm-12
          = f.label :opening_bal,"Opening Balance if any?", class: "col-sm-3 control-label text-right"
          = f.text_field :opening_bal, autofocus: true, class: "col-sm-3"
          = f.label :business_center,"From which business center invoice is being raised?", class: "col-sm-3 control-label text-right business_center-alignment"
          = f.select(:business_center, BusinessType.collect_business_type,{},{class: "selectpicker dropdown_business column-width-change", prompt: 'Select', "data-live-search": "true"})
    %br


    .fieldset
      .row
        .col-sm-3
          = f.submit "Save", class: "btn btn-primary"
        .col-sm-3
          = f.submit "cancel", type: :reset, class: "btn btn-primary"
        .col-sm-3
          - if @customer_detail.save
            = link_to "Download", download_csv_customer_detail_path(@customer_detail.id, format: "csv"), class: "btn btn-primary.disabled"
        .col-sm-3
          = link_to("Print", "javascript:print()", class: "btn btn-primary")



  我不知道如何在JS中为它写条件。有人请帮帮我。谢谢提前

1 个答案:

答案 0 :(得分:0)

disabled: true选项添加到Save按钮,并在使用Javascript / jQuery提交/保存表单时将其删除。通过AJAX提交表单将在这里派上用场。阅读this文章,了解如何通过Ruby on Rails中的AJAX处理表单提交。