Skip to content

Commit

Permalink
Some clean-up and change version num (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansg44 authored Jun 11, 2020
1 parent 4087524 commit 8ba436d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion main.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<span class="dropdown-item hidden-dropdown-item" id="show-all-rows-dropdown-item">Show all rows</span>
<span class="dropdown-item hidden-dropdown-item" id="show-valid-rows-dropdown-item">Show valid rows</span>
<span class="dropdown-item hidden-dropdown-item" id="show-invalid-rows-dropdown-item">Show invalid rows</span>
<span class="dropdown-item disabled" id="version-dropdown-item">Version 0.4.2</span>
<span class="dropdown-item disabled" id="version-dropdown-item">Version 0.5.0</span>
</div>
</div>
<button type="button" class="btn btn-primary" id="validate-btn">Validate</button>
Expand Down
25 changes: 12 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,6 @@ const changeRowVisibility = (id, invalidCells, hot) => {
HOT.updateSettings({hiddenRows: {rows: hiddenRows}});
}

const REGEX_DECIMAL = /^(-|\+|)(0|[1-9]\d*)(\.\d+)?$/

/**
* Get a collection of all invalid cells in the grid.
* @param {Object} hot Handsontable instance of grid.
Expand All @@ -606,6 +604,9 @@ const REGEX_DECIMAL = /^(-|\+|)(0|[1-9]\d*)(\.\d+)?$/
const getInvalidCells = (hot, data) => {
const invalidCells = {};
const fields = getFields(data);

const regexDecimal = /^(-|\+|)(0|[1-9]\d*)(\.\d+)?$/;

for (let row=0; row<hot.countRows(); row++) {
if (hot.isEmptyRow(row)) continue;

Expand All @@ -618,14 +619,13 @@ const getInvalidCells = (hot, data) => {
valid = fields[col].requirement !== 'required';
} else if (datatype === 'xs:nonNegativeInteger') {
const parsedInt = parseInt(cellVal, 10);
valid =
!isNaN(cellVal) && parsedInt >= 0 && parsedInt.toString()===cellVal
&& testNumericRange(parsedInt, fields[col])
valid = !isNaN(cellVal) && parsedInt>=0
valid &= parsedInt.toString()===cellVal;
valid &= testNumericRange(parsedInt, fields[col]);
} else if (datatype === 'xs:decimal') {
// Test against: 10 1 0 0.1 10e2 -1 0.0 0.0.2
const parsedDec = parseFloat(cellVal);
valid = !isNaN(cellVal) && REGEX_DECIMAL.test(cellVal)
&& testNumericRange(parsedDec, fields[col]);
valid = !isNaN(cellVal) && regexDecimal.test(cellVal);
valid &= testNumericRange(parsedDec, fields[col]);
} else if (datatype === 'xs:date') {
valid = moment(cellVal, 'YYYY-MM-DD', true).isValid();
} else if (datatype === 'select') {
Expand All @@ -648,11 +648,10 @@ const getInvalidCells = (hot, data) => {

/**
* Test a given number against an upper or lower range, if any.
@param {Number} number to be compared.
@param {Object} field that contains min and max limits.
@return {Boolean} validity of field.
@
*/
* @param {Number} number to be compared.
* @param {Object} field that contains min and max limits.
* @return {Boolean} validity of field.
*/
const testNumericRange = (number, field) => {

if (field['xs:minInclusive'] !== '') {
Expand Down

0 comments on commit 8ba436d

Please sign in to comment.