Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions frontend/src/components/manage/FormInputRow.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { createEventDispatcher } from "svelte";
import { createEventDispatcher, onMount } from "svelte";
const dispatch = createEventDispatcher();

import Input from "../form/Input.svelte";
Expand All @@ -19,7 +19,7 @@
export let formId;

export let data = {};
export let hasValidationErrors = false;
let hasValidationErrors = false;

// Initialize options if not present (for types that need options: 3, 21, 22)
$: if ((data.type === 3 || data.type === 21 || data.type === 22) && !data.options) {
Expand Down Expand Up @@ -96,7 +96,15 @@
$: hasInvalidDescription = data.description && data.description.length > 100;

// Overall validation error flag
$: hasValidationErrors = hasDuplicateValues || hasNoOptions || hasInvalidLabel || hasInvalidDescription;
$: {
hasValidationErrors = hasDuplicateValues || hasNoOptions || hasInvalidLabel || hasInvalidDescription;
dispatch('validationchange', hasValidationErrors);
}

// Also dispatch after mount — $: blocks run during init before listeners are guaranteed attached
onMount(() => {
dispatch('validationchange', hasValidationErrors);
});

$: windowWidth = 0;

Expand Down
9 changes: 7 additions & 2 deletions frontend/src/views/Forms.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
max_length: 255,
is_new: true,
type: 4, // Text Input
_key: Math.random(),
};

form.inputs = [...form.inputs, input];
Expand All @@ -150,7 +151,7 @@
let idx = form.inputs.findIndex((i) => i === input);

// Clean up validation error for the deleted input
delete inputValidationErrors[input.id || idx];
delete inputValidationErrors[input.id || input._key || idx];

form.inputs.splice(idx, 1);
for (let i = idx; i < form.inputs.length; i++) {
Expand Down Expand Up @@ -197,6 +198,7 @@
}

async function saveInputs() {
if (hasValidationErrors) return;
const form = getForm(activeFormId);

const data = {
Expand Down Expand Up @@ -374,7 +376,10 @@
withDirectionButtons={true}
index={i}
{formLength}
bind:hasValidationErrors={inputValidationErrors[input.id || i]}
on:validationchange={(e) => {
inputValidationErrors[input.id || input._key || i] = e.detail;
inputValidationErrors = inputValidationErrors;
}}
on:delete={() =>
deleteInput(activeFormId, input)}
on:move={(e) =>
Expand Down