diff --git a/data-table/__tests__/table.js b/data-table/__tests__/table.js index 7952c0b..c62eed4 100644 --- a/data-table/__tests__/table.js +++ b/data-table/__tests__/table.js @@ -551,3 +551,36 @@ describe('Test cell getters and setters', () => { expect(numErrorsVisible()).toEqual(0); }); }); + +describe('Serialization', () => { + beforeEach(() => { + table.createDataTable({ + 'wrapperDivId': 'div-id', + 'numRows': 1, + 'numColumns': 1 + }); + }); + + test('Default serialization', () => { + expect(table.toJSON('div-id')).toEqual(JSON.stringify({ + "version": 1, + "rowNames": [""], + "columnNames": [], + "data": [[{"Value": null, "Status": "Active"}]] + })); + }); + + test('Ensure number field doesn\'t allow commas', () => { + document.getElementById('div-id_row_1_and_col_1_and_field_0_').value = '1,000' + const serialized = table.toJSON('div-id'); + const numValue = JSON.parse(serialized).data[0][0].Value; + expect(numValue).toEqual(null); + }); + + test('Ensure number field correctly serializes', () => { + document.getElementById('div-id_row_1_and_col_1_and_field_0_').value = '1000' + const serialized = table.toJSON('div-id'); + const numValue = JSON.parse(serialized).data[0][0].Value; + expect(numValue).toEqual(1000); + }); +}); diff --git a/data-table/table.js b/data-table/table.js index 830d791..5e81e43 100644 --- a/data-table/table.js +++ b/data-table/table.js @@ -346,13 +346,20 @@ function createEntryCell(config, row, rowIndex, colIndex) { let field = null; let listener = null; // Each input type wants a different listener'focusout'; // usually we wan't a focusout, but not on dropdown - if (type === Number || type === String) { + if (type === String) { let input = document.createElement("INPUT"); input.type = 'text'; input.placeholder = config.datumConfig.values[fieldNum]; input.classList.add('dt_cell-input'); field = input; listener = 'focusout'; + } else if (type === Number) { + let input = document.createElement("INPUT"); + input.type = 'number'; + input.placeholder = config.datumConfig.values[fieldNum]; + input.classList.add('dt_cell-input'); + field = input; + listener = 'focusout'; } else if (type === Boolean) { let input = document.createElement("INPUT"); input.type = 'checkbox'; diff --git a/package.json b/package.json index 7b2342a..1ddfe04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "usfca-data-table", - "version": "0.0.5", + "version": "0.0.6", "description": "data table test", "main": "data-table/table.js", "directories": {