{"record":{"id":"7fea69530f1e8714","repo":"sveltejs/kit","slug":"cannot-mix-and-match-file-and-non-file-inputs-unde","errorCode":null,"errorMessage":"Cannot mix and match file and non-file inputs under the same name (\"${element.name}\")","messagePattern":"Cannot mix and match file and non-file inputs under the same name \\(\"(.+?)\"\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/remote-functions/form.svelte.js","lineNumber":525,"sourceCode":"\t\t\t\tconst is_file = element.type === 'file';\n\n\t\t\t\tif (field.is_array) {\n\t\t\t\t\tlet value;\n\n\t\t\t\t\tif (element.tagName === 'SELECT') {\n\t\t\t\t\t\tvalue = Array.from(\n\t\t\t\t\t\t\telement.querySelectorAll('option:checked'),\n\t\t\t\t\t\t\t(e) => /** @type {HTMLOptionElement} */ (e).value\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst elements = /** @type {HTMLInputElement[]} */ (\n\t\t\t\t\t\t\tArray.from(form.querySelectorAll(`[name=\"${name}\"]`))\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (DEV) {\n\t\t\t\t\t\t\tfor (const e of elements) {\n\t\t\t\t\t\t\t\tif ((e.type === 'file') !== is_file) {\n\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t`Cannot mix and match file and non-file inputs under the same name (\"${element.name}\")`\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tvalue = is_file\n\t\t\t\t\t\t\t? elements.map((input) => Array.from(input.files ?? [])).flat()\n\t\t\t\t\t\t\t: elements.map((element) => element.value);\n\t\t\t\t\t\tif (element.type === 'checkbox') {\n\t\t\t\t\t\t\tvalue = /** @type {string[]} */ (value.filter((_, i) => elements[i].checked));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tset_nested_value(input, field, is_file ? value : coerce_form_value(field.type, value));\n\t\t\t\t} else if (is_file) {\n\t\t\t\t\tif (DEV && element.multiple) {\n\t\t\t\t\t\tthrow new Error(","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/remote-functions/form.svelte.js#L507-L543","documentation":"In dev mode, SvelteKit inspects all inputs sharing a form control's name when a remote form is submitted. If some inputs with that name are type=file and others are not, the FormData serialization would be inconsistent between enhanced and native submissions, so it throws. This check only runs when DEV is true.","triggerScenarios":"Calling a remote form's submit/handle_input while the rendered <form> has multiple input elements sharing one name where at least one is type=\"file\" and at least one is not (e.g. a file input rendered conditionally alongside a text input with the same name).","commonSituations":"Conditionally rendering either a text or a file input under the same name; copying a name attribute across fields; dynamic forms where field type changes based on state.","solutions":["Give the file input a unique name distinct from non-file inputs","Ensure every input sharing a given name has the same type (all file or all non-file)","Remove the duplicate conditional input and use one input whose type/accept changes instead"],"exampleFix":"// before\n<input name=\"attachment\" type=\"text\" />\n{#if mode === 'upload'}\n  <input name=\"attachment\" type=\"file\" />\n{/if}\n// after\n<input name=\"attachment\" type=\"text\" />\n{#if mode === 'upload'}\n  <input name=\"attachment-file\" type=\"file\" />\n{/if}","handlingStrategy":"validation","validationCode":"function hasMixedInputTypes(form, name) {\n  const els = Array.from(form.querySelectorAll(`[name=\"${name}\"]`));\n  return els.some((e) => e.type === 'file') && els.some((e) => e.type !== 'file');\n}\n// call before submit; if true, rename inputs","typeGuard":"const isFileInput = (el) => el instanceof HTMLInputElement && el.type === 'file';","tryCatchPattern":null,"preventionTips":["Keep one input per name in remote forms","Never reuse a name across file and non-file inputs","Test enhanced forms in dev mode where this DEV check runs"],"tags":["dev-mode","formdata","remote-forms"],"backgroundTag":"mixed-file-and-non-file-inputs","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}