Skip to content

Commit

Permalink
feat: show errors when form has any invalid field
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Oct 20, 2023
1 parent 45846af commit 54e9eaf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/views/FormBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
type FormDefinition,
isValidFormDefinition,
FieldTypeReadable,
validateFields,
} from "src/core/formDefinition";
import { FolderSuggest } from "src/suggesters/suggestFolder";
import { setIcon, Setting, App } from "obsidian";
Expand All @@ -24,6 +25,7 @@
export let onPreview: (formDefinition: FormDefinition) => void;
$: isValid = isValidFormDefinition(definition);
$: errors = validateFields(definition.fields);
function folderField(element: HTMLElement, index: number) {
const field = definition.fields[index];
Expand Down Expand Up @@ -143,6 +145,22 @@
>Cancel</button
>
</div>
{#if errors.length > 0}
<h3 style="margin: 0;">
<span class="error">Form is invalid</span>, check the
following:
</h3>
<ul style="margin: 0;">
{#each errors as error}
<li>
{error.message}
{#if error.path}
at {error.path}
{/if}
</li>
{/each}
</ul>
{/if}
</fieldset>

<fieldset class="flex column gap2 fields">
Expand Down Expand Up @@ -396,6 +414,10 @@
.hint {
color: var(--color-base-70);
}
.error {
color: var(--text-error);
font-weight: bold;
}
button:disabled {
opacity: 0.5;
cursor: forbidden;
Expand Down

0 comments on commit 54e9eaf

Please sign in to comment.