-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing class to person role fields partial, add js method to mak…
…e remove roles work and update eventlistener of add role to correctly fire and trigger
- Loading branch information
1 parent
2495561
commit dde6985
Showing
4 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import "@hotwired/turbo-rails" | ||
import "./controllers" | ||
import "@puzzleitc/puzzle-shell"; | ||
import "@puzzleitc/puzzle-shell/style.css"; | ||
import "@puzzleitc/puzzle-shell/style.css"; | ||
require("./packs/nested-forms/addFields"); | ||
require("./packs/nested-forms/removeFields"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class removeFields { | ||
constructor() { | ||
this.iterateLinks(); | ||
} | ||
|
||
iterateLinks() { | ||
document.addEventListener("click", (e) => { | ||
if (e.target && e.target.className == "remove_fields") { | ||
this.handleClick(e.target, e); | ||
} | ||
}); | ||
} | ||
|
||
handleClick(link, e) { | ||
// Stop the function from executing if a link or event were not passed into the function. | ||
if (!link || !e) return; | ||
// Prevent the browser from following the URL. | ||
e.preventDefault(); | ||
// Find the parent wrapper for the set of nested fields. | ||
let fieldParent = link.closest(".nested-fields"); | ||
// If there is a parent wrapper, find the hidden delete field. | ||
let deleteField = fieldParent | ||
? fieldParent.querySelector('input[type="hidden"]') | ||
: null; | ||
// If there is a delete field, update the value to `1` and hide the corresponding nested fields. | ||
if (deleteField) { | ||
deleteField.value = 1; | ||
fieldParent.style.display = "none"; | ||
} | ||
} | ||
} | ||
window.addEventListener("turbo:frame-render", () => new removeFields()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters