tp-react-elements-dev 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Form/FormRender.d.ts +2 -0
- package/dist/index.esm.js +48 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +48 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -36,6 +36,8 @@ export interface FormSectionPropsItem {
|
|
|
36
36
|
sx?: SxProps<Theme>;
|
|
37
37
|
donotAllowSpace?: boolean;
|
|
38
38
|
onInputProps?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
39
|
+
fileType?: 'excel' | '';
|
|
40
|
+
handleFileError?: (message: string) => void;
|
|
39
41
|
}
|
|
40
42
|
export interface FormRenderProps {
|
|
41
43
|
item: FormSectionPropsItem;
|
package/dist/index.esm.js
CHANGED
|
@@ -52213,21 +52213,60 @@ const DatepickerWrapperV2 = ({ props }) => {
|
|
|
52213
52213
|
const FormRenderFileUpload = ({ props }) => {
|
|
52214
52214
|
var _a, _b, _c;
|
|
52215
52215
|
useEffect(() => {
|
|
52216
|
-
if (props.getValues(props.item.name) === null ||
|
|
52216
|
+
if (props.getValues(props.item.name) === null ||
|
|
52217
|
+
props.getValues(props.item.name) === undefined) {
|
|
52217
52218
|
const element = document.getElementById(props.item.name);
|
|
52218
|
-
console.log(element,
|
|
52219
|
+
console.log(element, "elementelement");
|
|
52219
52220
|
if (element) {
|
|
52220
|
-
element.value =
|
|
52221
|
+
element.value = ""; // Ensure it's an input element
|
|
52221
52222
|
}
|
|
52222
52223
|
}
|
|
52223
52224
|
}, [props.getValues(props.item.name)]);
|
|
52224
|
-
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs(Box, Object.assign({ paddingLeft: "4px" }, { children: [((_a = props.item) === null || _a === void 0 ? void 0 : _a.label) && jsxRuntimeExports.jsx(Box, Object.assign({ sx: { fontSize: "10px;" } }, { children: renderLabel((_b = props.item) === null || _b === void 0 ? void 0 : _b.label, (_c = props.item) === null || _c === void 0 ? void 0 : _c.required) })), jsxRuntimeExports.jsx(TextField, { type: "file", id: props.item.name, inputProps: {
|
|
52225
|
-
|
|
52226
|
-
|
|
52225
|
+
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs(Box, Object.assign({ paddingLeft: "4px" }, { children: [((_a = props.item) === null || _a === void 0 ? void 0 : _a.label) && (jsxRuntimeExports.jsx(Box, Object.assign({ sx: { fontSize: "10px;" } }, { children: renderLabel((_b = props.item) === null || _b === void 0 ? void 0 : _b.label, (_c = props.item) === null || _c === void 0 ? void 0 : _c.required) }))), jsxRuntimeExports.jsx(TextField, { type: "file", id: props.item.name, inputProps: {
|
|
52226
|
+
accept: props.item.fileType === "excel"
|
|
52227
|
+
? ".xls, .xlsx"
|
|
52228
|
+
: props.item.fileType === "pdf"
|
|
52229
|
+
? ".pdf"
|
|
52230
|
+
: props.item.fileType === "all"
|
|
52231
|
+
? ".pdf,.jpg,.jpeg,.png,.xls,.xlsx,.doc,.docx"
|
|
52232
|
+
: "",
|
|
52233
|
+
}, onChange: (event) => {
|
|
52234
|
+
var _a, _b, _c, _d, _e, _f;
|
|
52235
|
+
const file = event.target.files[0];
|
|
52227
52236
|
const fileName = file ? file.name : null;
|
|
52228
|
-
|
|
52229
|
-
|
|
52230
|
-
|
|
52237
|
+
const allowedExtensions = {
|
|
52238
|
+
excel: ["xls", "xlsx"],
|
|
52239
|
+
pdf: ["pdf"],
|
|
52240
|
+
all: ["pdf", "jpg", "jpeg", "png", "xls", "xlsx", "doc", "docx"],
|
|
52241
|
+
};
|
|
52242
|
+
const fileExtension = fileName
|
|
52243
|
+
? fileName.split(".").pop().toLowerCase()
|
|
52244
|
+
: null;
|
|
52245
|
+
const validExtensions = props.item.fileType === "excel"
|
|
52246
|
+
? allowedExtensions.excel
|
|
52247
|
+
: props.item.fileType === "pdf"
|
|
52248
|
+
? allowedExtensions.pdf
|
|
52249
|
+
: allowedExtensions.all;
|
|
52250
|
+
if (((_a = props.item) === null || _a === void 0 ? void 0 : _a.fileType) &&
|
|
52251
|
+
fileExtension &&
|
|
52252
|
+
!validExtensions.includes(fileExtension)) {
|
|
52253
|
+
((_b = props.item) === null || _b === void 0 ? void 0 : _b.handleFileError) && ((_c = props.item) === null || _c === void 0 ? void 0 : _c.handleFileError(`Please upload ${allowedExtensions[props.item.fileType].join(",")} Files only`));
|
|
52254
|
+
event.target.value = ""; // Clear the file input
|
|
52255
|
+
return;
|
|
52256
|
+
}
|
|
52257
|
+
// Proceed if valid
|
|
52258
|
+
props.setValue((_d = props.item) === null || _d === void 0 ? void 0 : _d.name, file);
|
|
52259
|
+
props.setValue(((_e = props.item) === null || _e === void 0 ? void 0 : _e.name) + "Name", fileName);
|
|
52260
|
+
(_f = props === null || props === void 0 ? void 0 : props.item) === null || _f === void 0 ? void 0 : _f.onChangeInput({
|
|
52261
|
+
[props.item.name]: file,
|
|
52262
|
+
[props.item.name + "Name"]: fileName,
|
|
52263
|
+
});
|
|
52264
|
+
// props.setValue(props.item?.name, file);
|
|
52265
|
+
// props.setValue(props.item?.name + "Name", fileName);
|
|
52266
|
+
// props?.item?.onChangeInput({
|
|
52267
|
+
// [props.item.name]: file,
|
|
52268
|
+
// [props.item.name + "Name"]: fileName,
|
|
52269
|
+
// });
|
|
52231
52270
|
}, sx: { width: "100%" } })] })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] }));
|
|
52232
52271
|
};
|
|
52233
52272
|
|