Skip to content

Surface invalid JSON errors in the create/duplicate event modal - #224

Merged
morcen merged 1 commit into
mainfrom
fix/issue-98-events-index-json-validation
Sep 14, 2026
Merged

morcen merged 1 commit into
mainfrom
fix/issue-98-events-index-json-validation

Conversation

@morcen

@morcen morcen commented Sep 13, 2026

Copy link
Copy Markdown
Owner

What was broken

On the Events index page, the "Create Event" / "Duplicate Event" modal (resources/js/Pages/Events/Index.vue) parsed the Payload and Schema textareas in a watch() callback:

watch(payloadText, (newValue) => {
    try {
        form.payload = newValue ? JSON.parse(newValue) : null
    } catch (e) {
        // Invalid JSON - will be handled by backend validation
    }
})

When JSON.parse threw, the catch block did nothing, so form.payload/form.schema silently retained their last successfully-parsed value. The comment's claim that "backend validation" would catch it was false — the invalid text was never sent anywhere, so the backend never saw it.

In practice: a user typing a Payload or Schema value with a JSON syntax error, then clicking Save, got a success response and redirect — but the stored payload/schema reflected stale (or null) data, not what they actually typed. Silent data loss with a false "success" signal.

This is the same class of bug already fixed on the event edit page in #223 — that fix only touched Edit.vue, leaving the create/duplicate modal in Index.vue with the original silent-catch bug.

What changed

Applied the same fix pattern used in #223 to Index.vue's create/duplicate modal:

  • Added payloadJsonError / schemaJsonError reactive state.
  • The watchers now set a descriptive error message when JSON.parse fails, instead of silently swallowing it, and clear the error (and null out the field) when the textarea is emptied.
  • InputError next to each textarea now shows payloadJsonError || form.errors.payload (and the schema equivalent).
  • The "Create" button is disabled while either field has a parse error, and saveEvent() bails out early if an error is present — so an Enter-triggered submit can't slip through either.
  • closeModal() resets the new error state alongside the existing form/text resets.

Tests

  • Added tests/Feature/DashboardEventCreateTest.php, covering that events.store persists the submitted payload/schema and rejects a duplicate event name for the same user.
  • Extended tests/e2e/specs/events.spec.ts with a case mirroring the one added for the edit page in Surface invalid JSON errors on the event edit page instead of silently discarding them #223, verifying the Create button disables and an "Invalid JSON" error appears when the payload textarea contains broken JSON, and that fixing the JSON clears the error and re-enables the button.
  • Ran the full suite (composer test): 252 passed, 1 pre-existing skip.

Fixes #98

…instead of silently discarding them

Events/Index.vue parsed the Payload/Schema textareas in a watcher and
swallowed JSON.parse errors, leaving form.payload/form.schema on their
last-valid value. Create Event then submitted successfully with the
stale data (or null, on first entry), so a user typing a broken
payload/schema in the create or duplicate modal saw a success message
while their actual input was silently dropped.

Track parse failures per field, surface them via InputError next to
the textarea, and block saveEvent() (both the button and Enter-triggered
submit) while either field is invalid, so the request is never sent
with data the user never intended to submit. This mirrors the fix
already applied to the event edit page in #223.

Fixes #98
@morcen
morcen merged commit 24893e4 into main Sep 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid JSON in Event Payload/Schema textareas is silently discarded; edits appear to save but the stale value is submitted instead

1 participant