Skip to content

Commit

Permalink
Merge pull request #5 from DaveElsensohn/master
Browse files Browse the repository at this point in the history
Adjusted hex validation, added formatting upon form save
  • Loading branch information
cjimti authored Jun 2, 2018
2 parents 4c8a752 + eaf0158 commit 7e4c959
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions www/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ body {
font-family: sans-serif;
color: white;
background-color: black;
margin: 0;
padding: 0;
}

.page {
Expand Down
9 changes: 5 additions & 4 deletions www/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function validateEndpoint(endpoint) {
* @return {boolean}
*/
function isHex(hex) {
const a = parseInt(hex, 16);
return (a.toString(16) === hex);
const re = /[0-9A-Fa-f]{6}/g;
return re.test(hex);
}

/**
Expand Down Expand Up @@ -215,13 +215,13 @@ function handleAddRule(evt) {
ruleDiv.classList.add('rule');

let fieldTotal = '<div class="field total">';
fieldTotal += '<label for="rule-value-' + idx + '">Value</label>';
fieldTotal += '<label for="rule-value-' + idx + '">Minimum Value</label>';
fieldTotal += '<input type="text" name="rule-value-' + idx + '" id="rule-value-' + idx + '" value="" placeholder="0">';
fieldTotal += '</div>';

let fieldHex = '<div class="field hex">';
fieldHex += '<label for="rule-hex-' + idx + '">Hex Color</label>';
fieldHex += '<input type="text" name="rule-hex-' + idx + '" id="rule-hex-' + idx + '" value="" placeholder="999999">';
fieldHex += '<input type="text" name="rule-hex-' + idx + '" id="rule-hex-' + idx + '" value="" placeholder="999999" maxlength="6">';
fieldHex += '</div>';

// let remove = '<a id="rule-remove-' + idx + '" class="btn btn-remove-rule" href="">X</a>';
Expand Down Expand Up @@ -271,6 +271,7 @@ function storeRules(evt) {
// Sort the rules in order and store
rulesArr.sort(compareValues('num'));
localStorage.setItem('rules', JSON.stringify(rulesArr));
formatMetric(metric.innerText);
ruleForm.classList.remove('active');
}

Expand Down

0 comments on commit 7e4c959

Please sign in to comment.