Below is the HTML element I'm using to show a loading spinner in my app, with mostly Bootstrap classes:
<div id="loadSpinner" class="overlay d-flex justify-content-center invisible">
...
</div>
Here is the form on view (Rails 6):
<%= form_with(url: result_path,
method: "patch", local: true) do |f| %>
...
<%= f.submit "Finish", class: "btn btn-success btn-lg my-3",
onclick: "finish();" %>
<% end %>
Here's the JavaScript function 'finish()' where we display the loading spinner:
function finish() {
...
document.querySelector('#loadSpinner').classList.remove('invisible');
}
Everything works smoothly in Chrome and Firefox, but sometimes the spinner fails to appear in Safari.
I've checked with console logs (
console.log(document.querySelector('#loadSpinner'))
) and confirmed that the 'invisible' class is indeed removed before submission. The JavaScript is functioning correctly, yet the spinner is not visible in Safari.
I even tried adding a 'visible' class after removing 'invisible', but the issue persists.
Does anyone have insight into why this might be happening specifically in Safari?
My theory is that perhaps the submission occurs before the 'invisible' class is fully removed, but I'm unsure how to verify and address it.