Sanitize fields before saving

This commit is contained in:
keplyx 2019-11-15 16:14:00 +01:00
parent 4e1ec778c1
commit 3c089f5d16

View file

@ -89,10 +89,10 @@ function getItemOfCode(code) {
function addNewItem() {
if (isItemInputFilled()) {
let item = {
name: $.selector_cache('#nameInput').val(),
description: $.selector_cache('#descriptionInput').val(),
quantity: $.selector_cache('#quantityInput').val(),
price: $.selector_cache('#priceInput').val(),
name: sanitizeString($.selector_cache('#nameInput').val()),
description: sanitizeString($.selector_cache('#descriptionInput').val()),
quantity: sanitizeNumber($.selector_cache('#quantityInput').val()),
price: sanitizeNumber($.selector_cache('#priceInput').val()),
code: $.selector_cache('#codeInput').val(),
type: getTypesChecked(),
image: $.selector_cache('#imageInput').val(),
@ -192,7 +192,13 @@ function saveDataset() {
SaveManager.saveData(currentTypes, currentDataset);
}
function sanitizeString(str) {
return str.trim();
}
function sanitizeNumber(nbrStr) {
return nbrStr.replace(/\s/g,'');
}
function scanArticle(code) {
let data = {