Browse Source

Sanitize fields before saving

keplyx 1 year ago
parent
commit
3c089f5d16
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      assets/js/stock.js

+ 10
- 4
assets/js/stock.js View File

@@ -89,10 +89,10 @@ function getItemOfCode(code) {
89 89
 function addNewItem() {
90 90
     if (isItemInputFilled()) {
91 91
         let item = {
92
-            name: $.selector_cache('#nameInput').val(),
93
-            description: $.selector_cache('#descriptionInput').val(),
94
-            quantity: $.selector_cache('#quantityInput').val(),
95
-            price: $.selector_cache('#priceInput').val(),
92
+            name: sanitizeString($.selector_cache('#nameInput').val()),
93
+            description: sanitizeString($.selector_cache('#descriptionInput').val()),
94
+            quantity: sanitizeNumber($.selector_cache('#quantityInput').val()),
95
+            price: sanitizeNumber($.selector_cache('#priceInput').val()),
96 96
             code: $.selector_cache('#codeInput').val(),
97 97
             type: getTypesChecked(),
98 98
             image: $.selector_cache('#imageInput').val(),
@@ -192,7 +192,13 @@ function saveDataset() {
192 192
     SaveManager.saveData(currentTypes, currentDataset);
193 193
 }
194 194
 
195
+function sanitizeString(str) {
196
+    return str.trim();
197
+}
195 198
 
199
+function sanitizeNumber(nbrStr) {
200
+    return nbrStr.replace(/\s/g,'');
201
+}
196 202
 
197 203
 function scanArticle(code) {
198 204
     let data = {

Loading…
Cancel
Save