formanitor 0.1.7 → 0.1.8
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/index.cjs +12 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4099,6 +4099,7 @@ var FormFileUploadWidget = ({
|
|
|
4099
4099
|
if (hadLocal) {
|
|
4100
4100
|
const next = Array.from(localFiles).filter((_, i) => i !== index);
|
|
4101
4101
|
if (next.length === 0) {
|
|
4102
|
+
store.setExternalError(fieldId, null);
|
|
4102
4103
|
setLocalFiles(null);
|
|
4103
4104
|
setValue(null);
|
|
4104
4105
|
return;
|
|
@@ -4113,14 +4114,17 @@ var FormFileUploadWidget = ({
|
|
|
4113
4114
|
}
|
|
4114
4115
|
if (allowMultiple && Array.isArray(value)) {
|
|
4115
4116
|
const next = value.filter((_, i) => i !== index);
|
|
4117
|
+
if (next.length === 0) store.setExternalError(fieldId, null);
|
|
4116
4118
|
setValue(next.length ? next : null);
|
|
4117
4119
|
return;
|
|
4118
4120
|
}
|
|
4121
|
+
store.setExternalError(fieldId, null);
|
|
4119
4122
|
setValue(null);
|
|
4120
4123
|
};
|
|
4121
4124
|
const handleChange = async (files) => {
|
|
4122
4125
|
setTouched();
|
|
4123
4126
|
if (!files || files.length === 0) {
|
|
4127
|
+
store.setExternalError(fieldId, null);
|
|
4124
4128
|
setLocalFiles(null);
|
|
4125
4129
|
setValue(null);
|
|
4126
4130
|
return;
|
|
@@ -4128,16 +4132,20 @@ var FormFileUploadWidget = ({
|
|
|
4128
4132
|
const selected = Array.from(files);
|
|
4129
4133
|
for (const file of selected) {
|
|
4130
4134
|
if (!matchesAccept(file, accept)) {
|
|
4131
|
-
|
|
4135
|
+
setLocalFiles(null);
|
|
4136
|
+
store.setExternalError(fieldId, `File type not allowed: ${file.name}`);
|
|
4132
4137
|
return;
|
|
4133
4138
|
}
|
|
4134
4139
|
if (file.size > maxSize) {
|
|
4135
|
-
|
|
4140
|
+
setLocalFiles(null);
|
|
4141
|
+
store.setExternalError(
|
|
4142
|
+
fieldId,
|
|
4136
4143
|
`File must be less than ${Math.round(maxSize / (1024 * 1024))}MB: ${file.name}`
|
|
4137
4144
|
);
|
|
4138
4145
|
return;
|
|
4139
4146
|
}
|
|
4140
4147
|
}
|
|
4148
|
+
store.setExternalError(fieldId, null);
|
|
4141
4149
|
const toUpload = allowMultiple ? selected : [selected[0]];
|
|
4142
4150
|
setLocalFiles(fileListFromArray(toUpload));
|
|
4143
4151
|
setIsUploading(true);
|
|
@@ -4153,10 +4161,11 @@ var FormFileUploadWidget = ({
|
|
|
4153
4161
|
const key = await uploadHandler(toUpload[0], toUpload[0].name);
|
|
4154
4162
|
setValue(key);
|
|
4155
4163
|
}
|
|
4164
|
+
store.setExternalError(fieldId, null);
|
|
4156
4165
|
} catch (err) {
|
|
4157
4166
|
console.error("[FormFileUpload] Upload failed:", err);
|
|
4158
4167
|
const message = err instanceof Error ? err.message : "Upload failed. Please try again.";
|
|
4159
|
-
|
|
4168
|
+
store.setExternalError(fieldId, message);
|
|
4160
4169
|
setLocalFiles(null);
|
|
4161
4170
|
setValue(null);
|
|
4162
4171
|
} finally {
|