Fix image upload validation and clearing

This commit is contained in:
2025-08-16 12:56:58 +02:00
parent 021bd8aae2
commit d65fe6e353

View File

@@ -14,14 +14,13 @@
></v-img>
</v-avatar>
//No funciona $clear
<v-file-input
accept="image/apng, image/avif, image/gif, image/jpeg, image/png, image/svg+xml, image/webp"
label="Subir imagen"
@input="handleFileInput"
type="file"
v-model="imagen"
click:clear="$clear"
click:clear="limpiar_input"
clearable
/><v-btn
color="secundary"
@@ -94,21 +93,23 @@ const uploadImage = async () => {
};
const validateFileType = () => {
var fileName = imagen.value.name;
var idxDot = fileName.lastIndexOf(".") + 1;
var extFile = fileName.substr(idxDot, fileName.length).toLowerCase();
if (
extFile == "jpg" ||
extFile == "jpeg" ||
extFile == "png" ||
extFile == "gif"
) {
return true;
} else {
alert("Only jpg, jpeg, png and gif files are allowed!");
files.value.pop();
imagen.value = null;
return false;
if (imagen.value != null) {
var fileName = imagen.value.name;
var idxDot = fileName.lastIndexOf(".") + 1;
var extFile = fileName.substr(idxDot, fileName.length).toLowerCase();
if (
extFile == "jpg" ||
extFile == "jpeg" ||
extFile == "png" ||
extFile == "gif"
) {
return true;
} else {
alert("Only jpg, jpeg, png and gif files are allowed!");
files.value.pop();
imagen.value = null;
return false;
}
}
};
@@ -120,6 +121,11 @@ const openImageDialog = () => {
// TODO Implement image dialog logic
};
const limpiar_input = () => {
imagen.value = null;
files.value.pop();
};
onMounted(async () => {
await listasStore.getData();
});