Last active
December 23, 2021 05:07
-
-
Save ridhotegar/60986b1146cee1718ceaf1d912ac795a to your computer and use it in GitHub Desktop.
validation all input
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
let checkInput = new Promise(function(solved, reject){ | |
let istirahat = {} | |
try { | |
document.querySelectorAll('input').forEach(function(el, index){ | |
if (!el.checkValidity()) { | |
alert(el.validationMessage) | |
el.focus() | |
throw istirahat | |
} else { | |
solved() | |
} | |
}) | |
} catch (e) { | |
if (e !== istirahat) throw e | |
} finally { | |
} | |
}) | |
checkInput.then(function(){ | |
let tambahData = { | |
vendorAsal: $('#vendor_asal').val(), | |
vendorTujuan: $('#vendor_tujuan').val(), | |
namaBarang: $('#barang').val(), | |
jumlah: $('#jumlah').val(), | |
keterangan: $('#keterangan').val() | |
} | |
data.push(tambahData) | |
document.querySelectorAll('input').forEach(function(el, index){ | |
if (el.name != 'kode') { | |
el.value = null | |
} | |
}) | |
updateTable() | |
}, null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment