Skip to content

Commit a355633

Browse files
authored
Merge pull request #9 from saicheck2233/issue#130_#144
Issue#130 and brutusin#144: Add collapsible form support
2 parents 0115dc3 + 9bff150 commit a355633

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/css/brutusin-json-forms.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,55 @@ form.brutusin-form .error {
115115
form.brutusin-form .error-message {
116116
color: red;
117117
}
118+
119+
.brutusin-card {
120+
position: relative;
121+
display: -webkit-box;
122+
display: -ms-flexbox;
123+
display: flex;
124+
-webkit-box-orient: vertical;
125+
-webkit-box-direction: normal;
126+
-ms-flex-direction: column;
127+
flex-direction: column;
128+
min-width: 0;
129+
word-wrap: break-word;
130+
background-color: #fff;
131+
background-clip: border-box;
132+
border: 1px solid rgba(0,0,0,.125);
133+
border-radius: 0.25rem;
134+
}
135+
136+
.brutusin-card-header {
137+
padding: 0.5rem 1.25rem;
138+
margin-bottom: 0;
139+
background-color: rgba(0,0,0,.03);
140+
border-bottom: 1px solid rgba(0,0,0,.125);
141+
}
142+
143+
.brutusin-card-body {
144+
-webkit-box-flex: 1;
145+
-ms-flex: 1 1 auto;
146+
flex: 1 1 auto;
147+
padding: 1.25rem;
148+
}
149+
150+
.brutusin-card-header a[data-toggle="collapse"]:after {
151+
font-family:'Bootstrap-icons';
152+
display: inline-block;
153+
content: "\F229";
154+
transition: all linear 0.25s;
155+
margin-left: 0.7rem;
156+
}
157+
158+
.brutusin-card-header a[data-toggle="collapse"].collapsed:after {
159+
transform: rotate(-180deg);
160+
}
161+
162+
#expand-btn.btn-link:focus, #expand-btn.btn-link:hover {
163+
text-decoration: unset;
164+
}
165+
166+
#expand-btn {
167+
display: flex;
168+
padding: 6px 0;
169+
}

src/js/brutusin-json-forms-bootstrap.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ if (("undefined" === typeof $ || "undefined" === typeof $.fn || "undefined" ===
5050
}
5151
}
5252
});
53+
54+
//Collapsible form
55+
BrutusinForms.addDecorator(function (element, schema) {
56+
if (schema !== undefined) {
57+
if (schema.collapsible !== undefined && schema.collapsible === true) {
58+
var parentElement = element.parentElement;
59+
var tagName = parentElement.tagName.toLowerCase();
60+
if (tagName === "form") {
61+
parentElement.className += " brutusin-card-body";
62+
var formParentElement = parentElement.parentElement;
63+
64+
var divCard = document.createElement("div");
65+
divCard.className = "brutusin-card";
66+
divCard.innerHTML = "<div class='brutusin-card-header'><a id='expand-btn' class='btn btn-link' data-toggle='collapse' data-target='#brutusin-form-collapsible' aria-expanded='true' aria-controls='brutusin-form-collapsible'></a></div>";
67+
68+
var divCardBody = document.createElement("div");
69+
divCardBody.className = "collapse in";
70+
divCardBody.id = "brutusin-form-collapsible";
71+
divCardBody.setAttribute("aria-expanded", "true");
72+
divCardBody.appendChild(parentElement);
73+
divCard.appendChild(divCardBody);
74+
75+
formParentElement.appendChild(divCard);
76+
77+
if (schema.title !== undefined) {
78+
document.getElementById("expand-btn").textContent = schema.title;
79+
}
80+
}
81+
}
82+
}
83+
});
5384

5485

5586
// Description help icon

0 commit comments

Comments
 (0)