var currentRowId=1; function renumberTableRows(){ var row_no=1; var table = document.getElementById("tabbody"); for (var i = 0, row; row = table.rows[i]; i++) { // row.cells[0].innerHTML=row_no++; } } function isFloat(val) { var floatRegex = /^-?\d+(?:[.,]\d*?)?$/; if (!floatRegex.test(val)) return false; val = parseFloat(val); if (isNaN(val)) return false; return true; } function deleteTableRow(rowId){ var target = document.getElementById("upload-target"+rowId); // this.message = app.message; var children = target.children; // delete all uploaded elements /* for (var i = 0; i < children.length; i++) { var tmp = children[i].getAttribute("data-id"); alert ("DEL"); alert (tmp); $K.ajax.post({ url: 'delete.php', data: 'id='+tmp, before: function(xhr) {}, success: function(response) {}, error: function(response) {} }); } */ // delete the row from table var element = document.getElementById("trow"+rowId); element.parentNode.removeChild(element); renumberTableRows(); // alert(rowId); } function showAlert(text) { $K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' }); return; } function reset2() { document.getElementById("a_type").value=""; document.getElementById("a_description").value=""; document.getElementById("a_amount").value=""; setUploadField(); } function addTableRow(){ var $node = $K.dom('#tabbody'); // create a new table row with id var element = document.createElement('tr'); element.setAttribute("id", "trow"+currentRowId); var a_type = document.getElementById("a_type").value; if (!a_type.trim().length ) { document.getElementById("a_type").focus(); showAlert("Bitte gib eine Auslagenart an!"); return; } var a_date = document.getElementById("a_date").value; if (!a_date.trim().length){ document.getElementById("a_date").focus(); showAlert("Bitte gib ein gültiges Datum an!"); return; } var a_description = document.getElementById("a_description").value; if (!a_description.trim().length){ document.getElementById("a_description").focus(); showAlert("Bitte gib eine Beschreibung ein!"); return; } var a_amount = document.getElementById("a_amount").value; if (!isFloat(a_amount)){ document.getElementById("a_amount").focus(); showAlert("Bitte gib einen gültigen Betrag ein!"); return; } var a_currency = document.getElementById("a_currency").value; if (!a_currency.trim().length){ document.getElementById("a_currency").focus(); showAlert("Bitte gib eine Währung an!"); return; } var target = document.getElementById("upload-target"+currentRowId); var children = target.children; if (!children.length){ showAlert("Bitte lade mindestens einen Beleg hoch!"); return; } /* a_type = "Hello";*/ var e=""; // add column for position no e += `${a_type}`; // add coluemn for a_type (Auslagenart) // e += ` `; e += `${a_date}`; // add column for date // e += ``; e += `${a_description}`; // add column for num e += `${a_amount}`; // add column for file upload /* e+= `
*/ e += `${a_currency}`; // `; // add delete bnutton e += ` `; $node.append(element); element.innerHTML=(e); // renumberTableRows(); currentRowId++; reset2(); } function setUploadField() { var e = $K.dom('#uploadfield'); var uf =`
Beleg hochladen
`; document.getElementById("uploadfield").innerHTML=uf; } $K.add('module', 'kaform', { init: function(app, context) { this.app = app; this.message = app.message; }, // catch event onmessage: { tabs: { opened: function(sender) { console.log('Tab box is ',sender.getActiveBox()); this.message.show({ message: 'My message' }); } } }, }); $K.init({ observer: true }); // startup is here // on startup clear session on server $K.ajax.get({ url: 'clear.php', data: '', // or key=value object before: function(xhr) {}, success: function(response) {}, error: function(response) {} }); setUploadField(); // add on table row //addTableRow();