Skip to content

Commit

Permalink
Defer validation to form change
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Apr 16, 2024
1 parent 0a47509 commit b722ac5
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import projectGlobalSchema from "../../../../../../../schemas/json/project/globa
import { merge } from "../../utils.js";
import { onThrow } from "../../../../errors";
import { header } from "../../../forms/utils";
import { preprocessMetadataSchema } from "../../../../../../../schemas/base-metadata.schema";

const projectMetadataSchema = merge(projectGlobalSchema, projectGeneralSchema);

const skipError = (message) => (message.includes("requires") && message.includes("name"));

export class GuidedNewDatasetPage extends Page {
constructor(...args) {
super(...args);
Expand All @@ -31,6 +32,13 @@ export class GuidedNewDatasetPage extends Page {
onNext: async () => {
const globalState = this.info.globalState.project;

this.dismiss(); // Dismiss all notifications

await this.form.validate().catch((error) => {
if (skipError(error.message)) return;
throw error;
})

// Check validity of project name
const name = this.state.name;
if (!name) {
Expand All @@ -39,10 +47,6 @@ export class GuidedNewDatasetPage extends Page {
return;
}

this.dismiss(); // Dismiss all notifications

await this.form.validate();

if (!name) return;

// Check if name is already used
Expand Down Expand Up @@ -86,7 +90,7 @@ export class GuidedNewDatasetPage extends Page {
this.form = new JSONSchemaForm({
schema,
results: this.state,
// validateEmptyValues: null,
validateEmptyValues: false,
dialogOptions: {
properties: ["createDirectory"],
},
Expand All @@ -95,7 +99,10 @@ export class GuidedNewDatasetPage extends Page {
},
validateOnChange,
onUpdate: () => (this.unsavedUpdates = true),
onThrow,
onThrow: function (message) {
if (skipError(message)) return;
onThrow(message);
}
});

return this.form;
Expand Down

0 comments on commit b722ac5

Please sign in to comment.