railsjquery将禁用下载按钮,直到保存表单为止
rails jquery disable the download button until the form is saved
视图
我创建了一个具有保存和下载按钮的表单。我希望在完成所有字段之前禁用保存按钮,并在保存表单之前禁用下载按钮。
- 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中为它写条件。请有人帮我。提前感谢
将disabled: true
选项添加到Save
按钮,并在使用Javascript/jQuery提交/保存表单时将其删除。通过AJAX提交表单将在这里派上用场。阅读本文,了解如何在RubyonRails中通过AJAX处理表单提交。
相关文章:
- 如何停止javascript的执行并允许用户保存表单
- javascript html使用webstorage保存表单
- 在浏览器会话中保存表单数据
- 空闲时自动保存表单
- 是否可以在没有用户提交表单的情况下保存表单数据
- 如何在单击“另存为草稿”按钮时使用 JavaScript 保存表单内容
- PHP 页面未保存表单和解析输出
- 使用 jquery 记住保存表单时打开的选项卡
- 使用ajax调用自动保存表单数据
- 如何在浏览器中保存表单输入
- 保存表单输入数据以在其他页面上使用
- Don't保存表单
- 如何在模态窗口中保存表单值
- 仅在提交时使用 javascript 保存表单状态
- 我如何保存表单数据与jquery和php sql
- 单击按钮保存表单中的数据
- 如何使用 HTML5 本地存储保存表单中的数据
- 如果用户没有保存表单,如何测试用户是否对表单进行了任何更改
- 如何保存表单中的信息?
- 通过ajax保存表单数据,不需要服务器代码