Skip to content

Commit 41b154d

Browse files
Added characters test in editor
Invalid exp changes button to disabled Invalid exp changes icon to warning Added style for disabled popup button and hover
1 parent db2a260 commit 41b154d

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Note: _The order of this list might not match the order these features will be a
6666

6767
_Release date: ???????????????????????_
6868

69-
_Work Time: 4h_
69+
_Work Time: 5h_
7070

7171
-
7272

pages/common.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,33 @@ editor.addEventListener('keyup', function (event) {
224224
// press 'Enter' to act as pressing the button
225225
if (event.key == 'Enter') button.click();
226226
}
227-
});
227+
});
228+
229+
// check for errors while typing
230+
textfield.addEventListener('input', checkErrors);
231+
232+
function checkErrors(event) {
233+
var inp = event.target.value.toString();
234+
235+
// check allowed characters => 0123456789.+-*/()
236+
var test = inp.match(/[0-9|\+|\-|\*|\/|(|)|\.]+/);
237+
if (!test) test = [""];
238+
239+
// if length of input = characters matched expression is valid
240+
if (inp.length === test[0].length) {
241+
button.disabled = false;
242+
showIcon(0);
243+
} else {
244+
button.disabled = true;
245+
showIcon(1);
246+
}
247+
248+
function showIcon(index) {
249+
icons.forEach(e => e.classList.add('invisible'));
250+
icons[index].classList.remove('invisible');
251+
}
252+
253+
// check if parentheses match
254+
255+
}
256+

pages/cylinder.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ <h4>Expression editor</h4>
129129
<p class="big">
130130
<span id="var">D</span>
131131
<span>=</span>
132-
<input type="text" name="expression" id="expression" placeholder="e.g.: 6+(25/2)">
132+
<input type="text" name="expression" id="expression" placeholder="0">
133133
<span>=</span>
134134
<span id="result">
135135
<num>0</num>

popup.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ close:hover {
8080
border-color: var(--color-1);
8181
}
8282

83+
.popup button:disabled,
84+
.popup button:disabled:hover {
85+
border-color: var(--color-2);
86+
color: var(--color-2);
87+
background-color: transparent;
88+
opacity: 50%;
89+
cursor: default;
90+
}
91+
8392
.popup button i {
8493
margin-right: 1ch;
8594
}

0 commit comments

Comments
 (0)