Browse Source

Sanitize fields before saving

keplyx 4 years 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
 function addNewItem() {
89
 function addNewItem() {
90
     if (isItemInputFilled()) {
90
     if (isItemInputFilled()) {
91
         let item = {
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
             code: $.selector_cache('#codeInput').val(),
96
             code: $.selector_cache('#codeInput').val(),
97
             type: getTypesChecked(),
97
             type: getTypesChecked(),
98
             image: $.selector_cache('#imageInput').val(),
98
             image: $.selector_cache('#imageInput').val(),
192
     SaveManager.saveData(currentTypes, currentDataset);
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
 function scanArticle(code) {
203
 function scanArticle(code) {
198
     let data = {
204
     let data = {

Loading…
Cancel
Save