@felte/common
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -19,5 +19,5 @@ import type { FormControl, Obj, FieldValue, Touched } from '../types'; | ||
}; | ||
export declare function setControlValue(el: FormControl, value: FieldValue | FieldValue[]): void; | ||
export declare function setControlValue(el: FormControl, value: FieldValue | FieldValue[] | FileList): void; | ||
/** Sets the form inputs value to match the data object provided. */ | ||
export declare function setForm<Data extends Obj>(node: HTMLFormElement, data: Data): void; | ||
//# sourceMappingURL=domUtils.d.ts.map |
@@ -19,5 +19,5 @@ import type { FormControl, Obj, FieldValue, Touched } from '../types'; | ||
}; | ||
export declare function setControlValue(el: FormControl, value: FieldValue | FieldValue[]): void; | ||
export declare function setControlValue(el: FormControl, value: FieldValue | FieldValue[] | FileList): void; | ||
/** Sets the form inputs value to match the data object provided. */ | ||
export declare function setForm<Data extends Obj>(node: HTMLFormElement, data: Data): void; | ||
//# sourceMappingURL=domUtils.d.ts.map |
@@ -155,4 +155,23 @@ import { isFormControl, isFieldSetElement, isInputElement, isSelectElement } from './typeGuards.js'; | ||
if (el.type === 'file') { | ||
el.files = null; | ||
el.value = ''; | ||
if (value instanceof FileList) { | ||
el.files = value; | ||
} | ||
else if (value instanceof File && typeof DataTransfer !== 'undefined') { | ||
const dataTransfer = new DataTransfer(); | ||
dataTransfer.items.add(value); | ||
el.files = dataTransfer.files; | ||
} | ||
else if (typeof DataTransfer !== 'undefined' && | ||
Array.isArray(value) && | ||
value.some((v) => v instanceof File)) { | ||
const dataTransfer = new DataTransfer(); | ||
for (const file of value) { | ||
file instanceof File && dataTransfer.items.add(file); | ||
} | ||
el.files = dataTransfer.files; | ||
} | ||
else if (!value || (Array.isArray(value) && !value.length)) { | ||
el.files = null; | ||
el.value = ''; | ||
} | ||
return; | ||
@@ -159,0 +178,0 @@ } |
{ | ||
"name": "@felte/common", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Common utilities for Felte packages", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
280412
2190