forked from fixin.me/fixin.me
Fix Units new/edit display on validation errors
Add test_new_and_edit_on_validation_error Closes #41
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<% link_id = dom_id(@unit.base || @unit, :add) %>
|
||||
<%= turbo_stream.disable link_id -%>
|
||||
|
||||
<%= turbo_stream.replace :unit_form do %>
|
||||
<%= form_with model: @unit, html: {id: :unit_form} do %>
|
||||
@@ -7,3 +6,4 @@
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.insert_form (@unit.base || :units), partial: 'form', locals: {link_id: link_id} %>
|
||||
<%= turbo_stream.disable link_id -%>
|
||||
|
||||
Reference in New Issue
Block a user