I am building a rails app that only deals with request json and will return the information to the user. I am trying to use the data-disable-with property, but after the action finish the button is not being enable.
I am requesting a Endpoint and the JSON response I will generate a XLSX file and send to the user.
The problem is that after the file has been send the button is not enable.
<%= form_for generate_report_path, url: generate_report_path(format: "xlsx"), method: :post do %>
<div class="form-group">
<%= label_tag(:dtInicio, "Data Inicio") %>
<%= text_field_tag(:dtInicio, nil, class: "form-control datepicker", id: 'cpDtInicio', placeholder: "Pesquise a data inicio", required: true) %>
</div>
<div class="form-group">
<%= label_tag(:dtFinal, "Data Final") %>
<%= text_field_tag(:dtFinal, nil, class: "form-control datepicker", id: 'cpDtFinal', placeholder: "Pesquise a data Final", required: true) %>
</div>
<%= button_tag("Download", class: "btn btn-dark", id: 'download', 'data-disable-with' => "<i class='fa fa-spinner fa-spin'></i> Gerando Relatório...") %>
<div class="col-md-12"></div>
<% end %>
On my controller:
def generate_report
begin_dt = Date.parse(params[:dtInicio]).strftime("%Y-%m-%d")
end_dt = Date.parse(params[:dtFinal]).strftime("%Y-%m-%d")
@info = JSON.parse(get_connection(begin_dt, end_dt))["information"]
respond_to do |format|
format.xlsx {
send_file generate_file, content_type: 'application/vnd.ms-excel',
filename: "#{Time.now.strftime('%Y%m%d%H%M%S%L')}.xlsx", :disposition => 'inline'
}
end
end
I already try to add a JS to enable, but the page is not reloading for this JS be executed. I'm lost and appreciate the help.