Skip to content

Commit

Permalink
chore: copy class to test
Browse files Browse the repository at this point in the history
  • Loading branch information
silvester-pari committed Jan 8, 2025
1 parent 7b02237 commit 01d38af
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion elements/jsonform/test/cases/load-custom-editor-interface.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
import { html } from "lit";
import { TEST_SELECTORS } from "../../src/enums";
import CustomEditorExample from "../../src/custom-inputs/example.js";

class CustomEditorExample extends JSONEditor.AbstractEditor {

Check failure on line 4 in elements/jsonform/test/cases/load-custom-editor-interface.js

View workflow job for this annotation

GitHub Actions / check-linting (ubuntu-latest, 20)

'JSONEditor' is not defined
build() {
super.build();

// control
this.control = document.createElement("div");

// Create a select element
this.input = document.createElement("select");
this.input.setAttribute("id", this.path + "test");
this.input.classList.add("form-select");

const options = [
{
value: "true",
label: "True",
data: true,
color: "green",
},
{
value: "false",
label: "False",
data: false,
color: "red",
},
];

// build options
options.forEach((option) => {
const optionElement = document.createElement("option");
optionElement.setAttribute("value", option.value);
optionElement.textContent = option.label;
optionElement.style.background = option.color;
optionElement.style.color = "white";
if (this.defaults.startVals[this.key] === option.data) {
optionElement.selected = true;
}
this.input.appendChild(optionElement);
});

// label
this.label = document.createElement("label");
this.label.setAttribute("for", this.path + "test");
this.label.classList.add("form-check-label");
this.label.textContent = this.schema.title;
this.label.style.fontStyle = "italic";

// appends
this.container.appendChild(this.control);
this.control.appendChild(this.label);
this.control.appendChild(this.input);
}

postBuild() {
super.postBuild();

this.input.addEventListener("change", (e) => {
e.preventDefault();
e.stopPropagation();
this.value = e.currentTarget.checked;
this.onChange(true);
});
}
}

// Destructure TEST_SELECTORS object
const { jsonForm } = TEST_SELECTORS;
Expand Down

0 comments on commit 01d38af

Please sign in to comment.