Skip to content

Commit

Permalink
Fix default values in fixtures app (#250)
Browse files Browse the repository at this point in the history
Currently the values shown on screen are auto-filled based on the schema. This includes selecting the first value of enum dropdowns. But the data saved in the textarea (which is ultimately sent to the API) doesn't have these which can cause confusion.

To ensure alignment, after filling in default values save the new data back to the textarea so that it represents what's actually being displayed.

This makes the textarea slightly harder to edit manually, but no-one's doing that anyway.

This replaces the `requestAnimationFrame` fix which just caused different issues.

#patch
  • Loading branch information
gregtyler authored Aug 14, 2024
1 parent a283f27 commit 03748d2
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions fixtures/static/js/json-schema-editor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class JsonSchemaEditor {
const value = JSON.parse(this.$module.value);

const data = jsonSchema.getTemplate(value);
this.$module.value = JSON.stringify(data);

this.$formContainer.innerHTML = "";
this.constructElements(this.$formContainer, data, jsonSchema);
Expand Down Expand Up @@ -186,10 +187,6 @@ export class JsonSchemaEditor {
$parent.appendChild(this.createGovukFormGroup(nub, $select));

$select.dispatchEvent(new InputEvent("input"));

requestAnimationFrame(() => {
$select.value = "";
});
} else if (schema.type === "string") {
const $input = document.createElement("input");
$input.id = `f-${pointer}`;
Expand Down

0 comments on commit 03748d2

Please sign in to comment.