Skip to content

Instantly share code, notes, and snippets.

@ridhotegar
Last active December 23, 2021 05:07
Show Gist options
  • Save ridhotegar/60986b1146cee1718ceaf1d912ac795a to your computer and use it in GitHub Desktop.
Save ridhotegar/60986b1146cee1718ceaf1d912ac795a to your computer and use it in GitHub Desktop.
validation all input
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