javascript - rails jquery disable the download button until the form is saved -


view

i have created form has save , download button. want save button disabled until completion of fields , download button disabled until form being saved.

- content_for :javascript_includes    = 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) |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 business center invoice 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")
dont know how write conditions in js.can please me.thanks in advance

add disabled: true option save button , remove when form submitted/saved using javascript/jquery. submitting form via ajax come in handy here. read this article learn how handle form submission via ajax in ruby on rails.


Comments