helpers: remove element immediately when no timeout is specified
This fixes an issue where clicking quickly on several "Remove row" buttons on a repetition field results in autosave errors. This is because the N+1 autosave request is correctly sent after the Nth response from the server, but _before_ the row element is actually removed from the DOM. So the N+1 request actually sends the fields for the deleted row, which makes the server raise an error. With this fix, the row gets properly removed when the server responds, and before the next request is started.
This commit is contained in:
parent
ecc4f01c20
commit
3fdecf0924
1 changed files with 5 additions and 1 deletions
|
@ -62,7 +62,11 @@ module ApplicationHelper
|
|||
script = "(function() {";
|
||||
script << "var el = document.querySelector('#{selector}');"
|
||||
method = (inner ? "el.innerHTML = ''" : "el.parentNode.removeChild(el)")
|
||||
script << "if (el) { setTimeout(function() { #{method}; }, #{timeout}); }";
|
||||
if timeout.present? && timeout > 0
|
||||
script << "if (el) { setTimeout(function() { #{method}; }, #{timeout}); }"
|
||||
else
|
||||
script << "if (el) { #{method} };"
|
||||
end
|
||||
script << "})();"
|
||||
# rubocop:disable Rails/OutputSafety
|
||||
raw(script);
|
||||
|
|
Loading…
Add table
Reference in a new issue