Skip to content

Commit

Permalink
Fixed SPA mode check for failStatus.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoheat committed Mar 11, 2024
1 parent 07ea90d commit a4e7761
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/lib/client/superForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export function superForm<
}

if (typeof options.SPA === 'string') {
// SPA action mode is "passive", no page updates are made.
if (options.invalidateAll === undefined) options.invalidateAll = false;
if (options.applyAction === undefined) options.applyAction = false;
}
Expand All @@ -435,7 +436,10 @@ export function superForm<
...options
};

if (options.SPA === true && options.validators === undefined) {
if (
(options.SPA === true || typeof options.SPA === 'object') &&
options.validators === undefined
) {
console.warn(
'No validators set for superForm in SPA mode. ' +
'Add a validation adapter to the validators option, or set it to false to disable this warning.'
Expand Down Expand Up @@ -642,6 +646,10 @@ export function superForm<
}
};

function Form_isSPA() {
return options.SPA === true || typeof options.SPA === 'object';
}

async function Form_validate(
opts: {
adapter?: FormOptions<T, M>['validators'];
Expand Down Expand Up @@ -1585,7 +1593,7 @@ export function superForm<
if (!cancelled) {
// Client validation
const noValidate =
!options.SPA &&
!Form_isSPA() &&
(FormElement.noValidate ||
((submit.submitter instanceof HTMLButtonElement ||
submit.submitter instanceof HTMLInputElement) &&
Expand Down Expand Up @@ -1638,7 +1646,7 @@ export function superForm<
// and accidentally removing errors set by setError
lastInputChange = undefined;

if (options.SPA === true) {
if (Form_isSPA()) {
if (!validation) validation = await validateForm();
cancel({ resetTimers: false });
clientValidationResult(validation);
Expand Down Expand Up @@ -1692,29 +1700,6 @@ export function superForm<
if (typeof options.SPA === 'string') {
ActionForm_setAction(options.SPA);
}

/*
if (typeof options.SPA === 'string') {
const absolute = /^(?:\/\/[a-z+]+:)/i.test(options.SPA);
if (!absolute) {
const split = options.SPA.indexOf('?');
if (split == -1) {
submitParams.action.pathname = options.SPA;
} else if (split == 0) {
submitParams.action.search = options.SPA;
} else {
submitParams.action.pathname = options.SPA.slice(0, split);
submitParams.action.search = options.SPA.slice(split);
}
}
console.log(
'SPA submit to',
submitParams.action.toString(),
Array.from(submitData.entries())
);
}
*/
}
}

Expand Down Expand Up @@ -1755,7 +1740,7 @@ export function superForm<
};

const unsubCheckforNav =
STORYBOOK_MODE || !options.SPA
STORYBOOK_MODE || !Form_isSPA()
? () => {}
: navigating.subscribe(($nav) => {
// Check for goto to a different route in the events
Expand Down

0 comments on commit a4e7761

Please sign in to comment.