Undead8 Undead8 - 3 months ago 54
Javascript Question

rails SweetAlert 2 not working in ie11

In my rails app, when the user clicks on a button, the browser sends a js post request, the controller calculates some stuff, then returns a js SweetAlert2 (swal) to the browser.

It works very well on chrome, firefox and safari. But on ie11, nothing happens when the button is clicked! Any idea why?

Here is the submit_tag button in the view that send the js post request.

<%= form_tag('check_exemption', remote: true) do %>
# Here are some radio buttons that are used to pass parameters to the controller.

<p><%= submit_tag('Check Exemption', class: 'btn btn-danger btn-block btn-xl') %></p>
<% end %>


Here is the route:

post ':action', to: 'protected_assets#check_exemption'


Here is the action in the protected_assets_controller:

def check_exemption
# Here the controller calculates some stuff to be returned in the swal below.

respond_to do |format|
format.html { redirect_to root_url }
format.js { render js: "swal('#{@financial_product.product_exemption_text}', '#{@financial_product.twelve_months_exempt_text} #{@financial_product.withdrawals_exemption_text}', '#{@financial_product.swal_type}')" }
end
end


Here is ie11 inspect panel where we see that the swal is returned correctly. However, the swal is not displayed on screen! Please note that the page is also not redirected to root_url like it should IF the request was a html request instead of js:

ie 11 panel

I'm a hobbyist new to rails, web development, javascript, html, css, etc. So please write your answer as if you were talking to a child or a wise dog.

Answer

I found my answer.

I am using the gem 'rails-assets-sweetalert2' from rails-assets.org. The instructions say that you only need to add //= require sweetalert2 in application.js.

However, I found out that you also need to add //= require es6-promise because the gem 'rails-assets-sweetalert2' is dependent on the gem 'rails-assets-es6-promise' for IE compatibility.

Everything now work as expected.

Comments