feature/campos-obligatorios-relativos
This commit is contained in:
@@ -125,6 +125,8 @@
|
||||
customs.advalorem_american = fraction.ad_valorem;
|
||||
}
|
||||
}
|
||||
|
||||
const isPackageRequired = $derived(!!quantities.package_id || (Number(quantities.package_quantity) > 0));
|
||||
</script>
|
||||
|
||||
<fieldset class="border rounded-md p-2 space-y-2">
|
||||
@@ -135,12 +137,18 @@
|
||||
|
||||
<div class="grid grid-cols-12 gap-2 items-end">
|
||||
<div class="col-span-2 space-y-1">
|
||||
<Label for="cantidad_bultos" class="text-xs">{m['invoice_item_fa.packages.quantity']()}: <span class="text-red-500">*</span></Label>
|
||||
<Label for="cantidad_bultos" class="text-xs">
|
||||
{m['invoice_item_fa.packages.quantity']()}:
|
||||
{#if isPackageRequired}<span class="text-red-500">*</span>{/if}
|
||||
</Label>
|
||||
<Input id="cantidad_bultos" type="number" step="1" min="0" bind:value={quantities.package_quantity} disabled={disabled} class="h-7 text-xs text-right" />
|
||||
</div>
|
||||
|
||||
<div class="col-span-3 space-y-1">
|
||||
<Label for="clave_bultos" class="text-xs">{m['invoice_item_fa.packages.package_code']()}: <span class="text-red-500">*</span></Label>
|
||||
<Label for="clave_bultos" class="text-xs">
|
||||
{m['invoice_item_fa.packages.package_code']()}:
|
||||
{#if isPackageRequired}<span class="text-red-500">*</span>{/if}
|
||||
</Label>
|
||||
<div class="flex gap-1">
|
||||
<Input
|
||||
id="clave_bultos"
|
||||
|
||||
@@ -316,13 +316,14 @@ function humanizeValidationMessage(message: string): string {
|
||||
.replace(/\b(value is not a valid integer)\b/gi, 'debe ser un número entero válido');
|
||||
}
|
||||
|
||||
function formatFriendlyFieldMessage(fieldName: string, message: string, code?: string): string {
|
||||
function formatFriendlyFieldMessage(fieldName: string, message: string, code?: string, fieldPath?: string): string {
|
||||
const cleanFieldName = fieldName.replace(/^Partida \d+ - /, '');
|
||||
const guidance = FIELD_GUIDANCE[cleanFieldName] || FIELD_GUIDANCE[fieldName];
|
||||
// Try to find guidance using the technical fieldPath first, then the humanized name
|
||||
const guidance = (fieldPath ? FIELD_GUIDANCE[fieldPath] : null) || FIELD_GUIDANCE[cleanFieldName] || FIELD_GUIDANCE[fieldName];
|
||||
const normalizedMessage = humanizeValidationMessage(message);
|
||||
|
||||
if (code === 'REQUIRED' || code === 'REQUIRED_FIELD' || /es requerido|es obligatorio/i.test(normalizedMessage)) {
|
||||
return guidance || `Completa ${fieldName}.`;
|
||||
return guidance || `Es obligatorio.`;
|
||||
}
|
||||
|
||||
if (code === 'AMERICAN_FRACTION_NOT_FOUND') {
|
||||
@@ -376,8 +377,9 @@ export function formatItemError(error: any): string {
|
||||
// New structure (ApiResponse.validationErrors)
|
||||
if (status === 422 && Array.isArray(validationErrors)) {
|
||||
const errors = validationErrors.map((err: any) => {
|
||||
const fieldName = humanizeFieldPath(err.field || '');
|
||||
const msg = formatFriendlyFieldMessage(fieldName, err.message || 'error de validación', err.code);
|
||||
const path = err.field || '';
|
||||
const fieldName = humanizeFieldPath(path);
|
||||
const msg = formatFriendlyFieldMessage(fieldName, err.message || 'error de validación', err.code, path.replace(/^line\[\d+\]\./, ''));
|
||||
|
||||
return `• ${fieldName}: ${msg}`;
|
||||
});
|
||||
@@ -393,7 +395,7 @@ export function formatItemError(error: any): string {
|
||||
.join('.');
|
||||
|
||||
const fieldName = humanizeFieldPath(locPath);
|
||||
const msg = formatFriendlyFieldMessage(fieldName, err.msg || 'error de validación', err.type);
|
||||
const msg = formatFriendlyFieldMessage(fieldName, err.msg || 'error de validación', err.type, locPath.replace(/^line\[\d+\]\./, ''));
|
||||
|
||||
return `• ${fieldName}: ${msg}`;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user