Fix Units new/edit display on validation errors

Add test_new_and_edit_on_validation_error
Closes #41
This commit is contained in:
2024-12-17 01:50:57 +01:00
parent f472526aa8
commit f0dab7a5f9
3 changed files with 38 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ Turbo.StreamElement.prototype.removePreviousForm = function(form) {
form.remove()
if (row) {
row.id = id
row.style.display = "revert"
row.removeAttribute("style")
}
if (form.hasAttribute("data-link-id")) {
const link = document.getElementById(form.getAttribute("data-link-id"))
@@ -71,9 +71,11 @@ Turbo.StreamActions.after_form = function() {
Turbo.StreamActions.replace_form = function() {
this.targetElements.forEach((e) => {
const id = e.id;
[...e.parentElement?.getElementsByClassName("form")].forEach((f) => {
this.removePreviousForm(f)
})
e = document.getElementById(id)
e.style.display = "none"
e.id = e.id + "_cached"
e.parentElement?.insertBefore(this.templateContent, e.nextSibling)