From 9bff1509b8fc5077cc149a211c43dc401ccd3d9a Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Sun, 2 Jul 2023 22:26:44 +0800 Subject: [PATCH] issue#130 and #144 --- src/css/brutusin-json-forms.css | 52 +++++++++++++++++++++++++ src/js/brutusin-json-forms-bootstrap.js | 31 +++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/src/css/brutusin-json-forms.css b/src/css/brutusin-json-forms.css index 86a5a2a..ecead7b 100644 --- a/src/css/brutusin-json-forms.css +++ b/src/css/brutusin-json-forms.css @@ -110,3 +110,55 @@ form.brutusin-form .error { form.brutusin-form .error-message { color: red; } + +.brutusin-card { + position: relative; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -ms-flex-direction: column; + flex-direction: column; + min-width: 0; + word-wrap: break-word; + background-color: #fff; + background-clip: border-box; + border: 1px solid rgba(0,0,0,.125); + border-radius: 0.25rem; +} + +.brutusin-card-header { + padding: 0.5rem 1.25rem; + margin-bottom: 0; + background-color: rgba(0,0,0,.03); + border-bottom: 1px solid rgba(0,0,0,.125); +} + +.brutusin-card-body { + -webkit-box-flex: 1; + -ms-flex: 1 1 auto; + flex: 1 1 auto; + padding: 1.25rem; +} + +.brutusin-card-header a[data-toggle="collapse"]:after { + font-family:'Bootstrap-icons'; + display: inline-block; + content: "\F229"; + transition: all linear 0.25s; + margin-left: 0.7rem; +} + +.brutusin-card-header a[data-toggle="collapse"].collapsed:after { + transform: rotate(-180deg); +} + +#expand-btn.btn-link:focus, #expand-btn.btn-link:hover { + text-decoration: unset; +} + +#expand-btn { + display: flex; + padding: 6px 0; +} \ No newline at end of file diff --git a/src/js/brutusin-json-forms-bootstrap.js b/src/js/brutusin-json-forms-bootstrap.js index b29e630..9248e12 100644 --- a/src/js/brutusin-json-forms-bootstrap.js +++ b/src/js/brutusin-json-forms-bootstrap.js @@ -50,6 +50,37 @@ if (("undefined" === typeof $ || "undefined" === typeof $.fn || "undefined" === } } }); + + //Collapsible form + BrutusinForms.addDecorator(function (element, schema) { + if (schema !== undefined) { + if (schema.collapsible !== undefined && schema.collapsible === true) { + var parentElement = element.parentElement; + var tagName = parentElement.tagName.toLowerCase(); + if (tagName === "form") { + parentElement.className += " brutusin-card-body"; + var formParentElement = parentElement.parentElement; + + var divCard = document.createElement("div"); + divCard.className = "brutusin-card"; + divCard.innerHTML = "
"; + + var divCardBody = document.createElement("div"); + divCardBody.className = "collapse in"; + divCardBody.id = "brutusin-form-collapsible"; + divCardBody.setAttribute("aria-expanded", "true"); + divCardBody.appendChild(parentElement); + divCard.appendChild(divCardBody); + + formParentElement.appendChild(divCard); + + if (schema.title !== undefined) { + document.getElementById("expand-btn").textContent = schema.title; + } + } + } + } + }); // Description help icon