Surface invalid JSON errors in the create/duplicate event modal - #224
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 awatch()callback:When
JSON.parsethrew, thecatchblock did nothing, soform.payload/form.schemasilently 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 inIndex.vuewith the original silent-catch bug.What changed
Applied the same fix pattern used in #223 to
Index.vue's create/duplicate modal:payloadJsonError/schemaJsonErrorreactive state.JSON.parsefails, instead of silently swallowing it, and clear the error (and null out the field) when the textarea is emptied.InputErrornext to each textarea now showspayloadJsonError || form.errors.payload(and the schema equivalent).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
tests/Feature/DashboardEventCreateTest.php, covering thatevents.storepersists the submitted payload/schema and rejects a duplicate event name for the same user.tests/e2e/specs/events.spec.tswith 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.composer test): 252 passed, 1 pre-existing skip.Fixes #98