Skip to content

Commit

Permalink
Prevent saving invalid form (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored Feb 5, 2024
2 parents 4fa3df1 + dc01f23 commit 30720a6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/client/cypress/e2e/editor/completion.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,18 @@ describe("completion crud tests", () => {
expect(location.hash).to.eq("#casing");
});

// new to existing: changes can be reverted in prompt
// new to existing: save option is disabled if form is invalid
addCompletion();
cy.location().should(location => {
expect(location.pathname).to.eq(`/editor/${boreholeId}/completion/new`);
expect(location.hash).to.eq("");
});
setInput("name", "new completion");
setTab(0);
cy.get('[data-cy="prompt-button-save"]').should("be.disabled");
handlePrompt("Unsaved changes", "cancel");

// new to existing: changes can be reverted in prompt
setSelect("kindId", 1);
setTab(0);
handlePrompt("Unsaved changes", "reset");
Expand Down Expand Up @@ -317,16 +322,24 @@ describe("completion crud tests", () => {
setTab(2);
deleteCompletion();
handlePrompt("Do you really want to delete this completion?", "delete");
cy.location().should(location => {
expect(location.pathname).to.eq(
`/editor/${boreholeId}/completion/${completion2Id}`,
);
expect(location.hash).to.eq("#casing");
});

// existing editing to new: no prompt should be displayed when no changes have been made, form should be reset
setTab(0);
startEditing();
cy.wait("@casing_GET");
isTabSelected(0);
cy.location().should(location => {
expect(location.pathname).to.eq(
`/editor/${boreholeId}/completion/${completion1Id}`,
);
expect(location.hash).to.eq("#casing");
});
startEditing();
cy.get(`[data-cy="name-formInput"]`).click();
addCompletion();
evaluateInput("name", "");
Expand Down
2 changes: 1 addition & 1 deletion src/client/public/locale/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"uploaded": "Hochgeladen",
"uploadNewFile": "Hochladen einer neuen Datei",
"unsavedChangesTitle": "Ungespeicherte Änderungen",
"unsavedChangesMessage": "Sie haben ungespeicherte Änderungen. Wollen Sie sie speichern?",
"unsavedChangesMessage": "Sie haben ungespeicherte Änderungen. Wie möchten Sie fortfahren?",
"unselectAll": "Alle abwählen",
"user": "Benutzer",
"username": "Benutzername",
Expand Down
2 changes: 1 addition & 1 deletion src/client/public/locale/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"uploaded": "Uploaded",
"uploadNewFile": "Upload a new file",
"unsavedChangesTitle": "Unsaved changes",
"unsavedChangesMessage": "You have unsaved changes. Do you want to save them?",
"unsavedChangesMessage": "You have unsaved changes. How would you like to proceed?",
"unselectAll": "Unselect all",
"user": "User",
"username": "Username",
Expand Down
2 changes: 1 addition & 1 deletion src/client/public/locale/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"uploaded": "Téléchargé",
"uploadNewFile": "Télécharger un nouveau fichier",
"unsavedChangesTitle": "Changements non enregistrés",
"unsavedChangesMessage": "Vous avez des modifications non enregistrés. Voulez-vous les enregistrer?",
"unsavedChangesMessage": "Vous avez des modifications non enregistrés. Comment souhaitez-vous continuer?",
"unselectAll": "Tout désélectionner",
"user": "Utilisateur",
"username": "Nom d'utilisateur",
Expand Down
2 changes: 1 addition & 1 deletion src/client/public/locale/it/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"uploaded": "Caricamento",
"uploadNewFile": "Caricare un nuovo file",
"unsavedChangesTitle": "Modifiche non salvate",
"unsavedChangesMessage": "Le modifiche non sono state salvate. Volete salvarle?",
"unsavedChangesMessage": "Le modifiche non sono state salvate. Come volete procedere?",
"unselectAll": "Deseleziona tutto",
"user": "Utente",
"username": "Nome utente",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const CompletionHeaderInput = props => {
},
{
label: "save",
disabled: !formMethods.formState.isValid,
action: () => {
formMethods.handleSubmit(submitForm)();
},
Expand Down
1 change: 1 addition & 0 deletions src/client/src/components/prompt/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Prompt = props => {
}
setOpen(false);
}}
disabled={action.disabled === true}
data-cy={"prompt-button-" + action.label}>
{t(action.label)}
</PromptButton>
Expand Down

0 comments on commit 30720a6

Please sign in to comment.