-
-
Save parzibyte/5b1d414db6e0305a7efc8a6b5038429b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TOTAL_VENTA = 30; | |
const resultado = await Swal | |
.fire({ | |
title: "Escriba el pago del cliente para calcular el cambio", | |
input: "number", | |
inputValidator: pago => { | |
if (!pago || pago < TOTAL_VENTA) { | |
return "El pago debe ser mayor o igual al total de la venta"; | |
} else { | |
return undefined; | |
} | |
}, | |
html: ` | |
<h2>Total: <small >$${TOTAL_VENTA.toFixed(2)}</small></h2> | |
<h1>Cambio: <small id="cambio"></small></h1> | |
`, | |
didOpen: () => { | |
const input = Swal.getInput() | |
const $cambio = Swal.getHtmlContainer().querySelector( | |
"#cambio"); | |
input.oninput = () => { | |
$cambio.textContent = ""; | |
const cambio = parseFloat(input.value) - TOTAL_VENTA; | |
if (cambio > 0) { | |
$cambio.textContent = `$${cambio.toFixed(2)}`; | |
} | |
} | |
}, | |
showCancelButton: true, | |
confirmButtonText: "Ok", | |
cancelButtonText: "Cancelar", | |
}); | |
if (resultado.value) { | |
const input = Object.assign(document.createElement("input"), { | |
value: "terminar", | |
name: "accion", | |
type: "hidden", | |
}); | |
$formularioTerminarVenta.append(input); | |
$formularioTerminarVenta.submit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment