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.mjs CHANGED
@@ -4064,6 +4064,7 @@ var FormFileUploadWidget = ({
4064
4064
  if (hadLocal) {
4065
4065
  const next = Array.from(localFiles).filter((_, i) => i !== index);
4066
4066
  if (next.length === 0) {
4067
+ store.setExternalError(fieldId, null);
4067
4068
  setLocalFiles(null);
4068
4069
  setValue(null);
4069
4070
  return;
@@ -4078,14 +4079,17 @@ var FormFileUploadWidget = ({
4078
4079
  }
4079
4080
  if (allowMultiple && Array.isArray(value)) {
4080
4081
  const next = value.filter((_, i) => i !== index);
4082
+ if (next.length === 0) store.setExternalError(fieldId, null);
4081
4083
  setValue(next.length ? next : null);
4082
4084
  return;
4083
4085
  }
4086
+ store.setExternalError(fieldId, null);
4084
4087
  setValue(null);
4085
4088
  };
4086
4089
  const handleChange = async (files) => {
4087
4090
  setTouched();
4088
4091
  if (!files || files.length === 0) {
4092
+ store.setExternalError(fieldId, null);
4089
4093
  setLocalFiles(null);
4090
4094
  setValue(null);
4091
4095
  return;
@@ -4093,16 +4097,20 @@ var FormFileUploadWidget = ({
4093
4097
  const selected = Array.from(files);
4094
4098
  for (const file of selected) {
4095
4099
  if (!matchesAccept(file, accept)) {
4096
- alert(`File type not allowed: ${file.name}`);
4100
+ setLocalFiles(null);
4101
+ store.setExternalError(fieldId, `File type not allowed: ${file.name}`);
4097
4102
  return;
4098
4103
  }
4099
4104
  if (file.size > maxSize) {
4100
- alert(
4105
+ setLocalFiles(null);
4106
+ store.setExternalError(
4107
+ fieldId,
4101
4108
  `File must be less than ${Math.round(maxSize / (1024 * 1024))}MB: ${file.name}`
4102
4109
  );
4103
4110
  return;
4104
4111
  }
4105
4112
  }
4113
+ store.setExternalError(fieldId, null);
4106
4114
  const toUpload = allowMultiple ? selected : [selected[0]];
4107
4115
  setLocalFiles(fileListFromArray(toUpload));
4108
4116
  setIsUploading(true);
@@ -4118,10 +4126,11 @@ var FormFileUploadWidget = ({
4118
4126
  const key = await uploadHandler(toUpload[0], toUpload[0].name);
4119
4127
  setValue(key);
4120
4128
  }
4129
+ store.setExternalError(fieldId, null);
4121
4130
  } catch (err) {
4122
4131
  console.error("[FormFileUpload] Upload failed:", err);
4123
4132
  const message = err instanceof Error ? err.message : "Upload failed. Please try again.";
4124
- alert(message);
4133
+ store.setExternalError(fieldId, message);
4125
4134
  setLocalFiles(null);
4126
4135
  setValue(null);
4127
4136
  } finally {