Skip to content

Commit

Permalink
Hide disabled properties on the preform
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Mar 25, 2024
1 parent de93c84 commit 8da2baf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const componentCSS = `
gap: 10px;
}
.form-section[hidden] {
display: none;
}
#empty {
display: flex;
align-items: center;
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/src/stories/pages/guided-mode/setup/Preform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const questions = {
condition: [false, undefined],
default: "",
required: true,
attribute: "hidden",
},
},
},
Expand All @@ -33,7 +32,6 @@ const questions = {
condition: [false, undefined],
default: "",
required: true,
attribute: "hidden",
},
},
},
Expand Down Expand Up @@ -127,8 +125,9 @@ export class GuidedPreform extends Page {
});

const dependentEl = this.inputs[dependent.name];
const dependentParent = dependentEl.parentElement

const attr = dependent.attribute ?? "disabled";
const attr = dependent.attribute ?? "hidden";

let condition = (v) => !!v;
if (!("condition" in dependent)) {
Expand All @@ -138,13 +137,13 @@ export class GuidedPreform extends Page {
else console.warn("Invalid condition", dependent.condition);

if (uniformDeps.every(({ name }) => condition(parent[name]))) {
dependentEl.removeAttribute(attr);
dependentParent.removeAttribute(attr);
if ("required" in dependent) dependentEl.required = dependent.required;
if ("__cached" in dependent) dependentEl.updateData(dependent.__cached);
} else {
if (dependentEl.value !== undefined) dependent.__cached = dependentEl.value;
dependentEl.updateData(dependent.default);
dependentEl.setAttribute(attr, true);
dependentParent.setAttribute(attr, true);
if ("required" in dependent) dependentEl.required = !dependent.required;
}
});
Expand Down

0 comments on commit 8da2baf

Please sign in to comment.