Skip to content

Commit 7097f74

Browse files
committed
Fixed constraints on fields that starts with a number.
Fixes #285
1 parent 62dbebc commit 7097f74

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Timers weren't starting until after `onSubmit`, allowing multiple form submissions on longer async operations. ([#284](https://github.com/ciscoheat/sveltekit-superforms/issues/284))
13+
- Fixed constraints on fields that starts with a number. ([#285](https://github.com/ciscoheat/sveltekit-superforms/issues/285))
1314

1415
## [1.10.0] - 2023-11-07
1516

src/lib/client/clientValidation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async function _clientValidation<T extends AnyZodObject, M = unknown>(
133133

134134
await traversePathsAsync(checkData, async ({ value, path }) => {
135135
// Filter out array indices, the validator structure doesn't contain these.
136-
const validationPath = path.filter((p) => isNaN(parseInt(p)));
136+
const validationPath = path.filter((p) => /\D/.test(String(p)));
137137
const maybeValidator = traversePath(
138138
validator,
139139
validationPath as FieldPath<typeof validator>
@@ -392,7 +392,7 @@ async function _validateField<T extends ZodValidation<AnyZodObject>, M>(
392392
shouldUpdate: true,
393393
currentData: undefined as z.infer<T> | undefined,
394394
// Remove numeric indices, they're not used for validators.
395-
validationPath: path.filter((p) => isNaN(parseInt(p)))
395+
validationPath: path.filter((p) => /\D/.test(String(p)))
396396
};
397397

398398
async function defaultValidate() {

src/lib/client/proxies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function formFieldProxy<
282282
const path2 = splitPath<z.infer<UnwrapEffects<T>>>(path);
283283
// Filter out array indices, the constraints structure doesn't contain these.
284284
const constraintsPath = (path2 as unknown[])
285-
.filter((p) => isNaN(parseInt(String(p))))
285+
.filter((p) => /\D/.test(String(p)))
286286
.join('.');
287287

288288
const taintedProxy = derived<

src/lib/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function mapErrors<T extends AnyZodObject>(
8888
for (const [key, value] of entries.filter(([key]) => key !== '_errors')) {
8989
// Keep current errorShape if the object key is numeric
9090
// which means we are in an array.
91-
const numericKey = !isNaN(parseInt(key, 10));
91+
const numericKey = /^\d+$/.test(key);
9292

9393
// _errors are filtered out, so casting is fine
9494
output[key] = mapErrors(

0 commit comments

Comments
 (0)