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