Skip to content

Commit 7a6276e

Browse files
committed
Show/hide itemCount input in demo conditionally
Depending on the value of multilineLists config
1 parent f293509 commit 7a6276e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

static/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,16 @@ <h3 style="margin: 0.5rem 0">Options</h3>
9292
<option value="always">Always</option>
9393
<option value="avoid">Avoid</option>
9494
<option value="expressionWidth">Expression width</option>
95+
<option value="itemCount">Item count</option>
9596
</select>
96-
</article>
97-
<article class="config">
98-
<label for="multilineLists.itemCount">Newline item count:</label>
9997
<input
10098
type="number"
101-
id="multilineLists.itemCount"
102-
name="multilineLists.itemCount"
103-
min="0"
99+
id="multilineLists-itemCount"
100+
name="multilineLists-itemCount"
101+
min="1"
104102
max="100"
105-
value="0"
103+
value="1"
104+
style="display: none"
106105
/>
107106
</article>
108107
<article class="config">

static/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const attachFormat = () => {
99
const logicalOperatorNewline = document.getElementById('logicalOperatorNewline');
1010
const aliasAs = document.getElementById('aliasAs');
1111
const multilineLists = document.getElementById('multilineLists');
12-
const itemCount = document.getElementById('multilineLists.itemCount');
12+
const itemCount = document.getElementById('multilineLists-itemCount');
1313
const tabulateAlias = document.getElementById('tabulateAlias');
1414
const commaPosition = document.getElementById('commaPosition');
1515
const newlineBeforeOpenParen = document.getElementById('newlineBeforeOpenParen');
@@ -20,6 +20,12 @@ const attachFormat = () => {
2020
const newlineBeforeSemicolon = document.getElementById('newlineBeforeSemicolon');
2121

2222
function format() {
23+
if (multilineLists.options[multilineLists.selectedIndex].value === 'itemCount') {
24+
itemCount.style.display = 'inline';
25+
} else {
26+
itemCount.style.display = 'none';
27+
}
28+
2329
try {
2430
const config = {
2531
language: language.options[language.selectedIndex].value,
@@ -31,7 +37,7 @@ const attachFormat = () => {
3137
logicalOperatorNewline.options[logicalOperatorNewline.selectedIndex].value,
3238
aliasAs: aliasAs.options[aliasAs.selectedIndex].value,
3339
multilineLists:
34-
itemCount.value > 0
40+
multilineLists.options[multilineLists.selectedIndex].value === 'itemCount'
3541
? itemCount.value
3642
: multilineLists.options[multilineLists.selectedIndex].value,
3743
tabulateAlias: tabulateAlias.checked,

0 commit comments

Comments
 (0)