feat: jqValidateForm에 Values Type 지정
This commit is contained in:
@@ -3,7 +3,7 @@ import { isArray, isString, isNumber, isBoolean } from "lodash";
|
||||
export function convertFormData(values: Record<string, null|number[]|string[]|boolean[]|number|string|boolean>): FormData{
|
||||
const formData = new FormData();
|
||||
|
||||
const simpleConv = (v: unknown):string=>{
|
||||
const simpleConv = (v: unknown, key: string):string=>{
|
||||
if(isString(v)){
|
||||
return v;
|
||||
}
|
||||
@@ -16,19 +16,19 @@ export function convertFormData(values: Record<string, null|number[]|string[]|bo
|
||||
if(v===null){
|
||||
return '';
|
||||
}
|
||||
throw new TypeError('지원하지 않는 formData Type');
|
||||
throw new TypeError(`지원하지 않는 formData Type: ${key}`);
|
||||
}
|
||||
|
||||
for(const [key, value] of Object.entries(values)){
|
||||
if(isArray(value)){
|
||||
const arrKey = `${key}[]`;
|
||||
for(const subValue of value){
|
||||
formData.append(arrKey, simpleConv(subValue));
|
||||
formData.append(arrKey, simpleConv(subValue, key));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
formData.append(key, simpleConv(value));
|
||||
formData.append(key, simpleConv(value, key));
|
||||
}
|
||||
|
||||
return formData;
|
||||
|
||||
Reference in New Issue
Block a user