Skip to content

Commit 4482459

Browse files
committed
Radio and select field options
1 parent 4a280e5 commit 4482459

4 files changed

Lines changed: 81 additions & 14 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ commtrackr.init({ // Initialize CommTracker with configurations
7575
fields: [
7676
{
7777
id: 'name', // Unique identifier for the field
78-
type: 'text', // Field type (e.g., text, number, date, textarea, checkbox)
78+
type: 'text', // Field type (e.g., text, number, date, textarea, checkbox, radio, select)
7979
label: 'Website Name', // Field label
8080
description: 'The name of the website or project.', // Field description
8181
placeholder: 'e.g. My Website', // Placeholder text for the field
8282
required: true // Whether the field is required
83+
options: [ // Options for select or radio fields
84+
{
85+
label: 'Option 1', // Option label
86+
value: 'option1' // Option value
87+
}
88+
],
8389
},
8490
],
8591
});

frontend/pages/user.ejs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
<% } else if (field.type === 'checkbox') { %>
1212
<input type="checkbox" class="hidden">
1313
<div class="checkbox" change="cms">|||</div>
14+
<% } else if (field.type === 'radio') { %>
15+
<div class="radioOptions">
16+
<% (field.options || []).forEach(option => { %>
17+
<div class="radioOption">
18+
<input type="radio" id="<%= option.value %>" name="<%= option.value %>" value="<%= option.label %>">
19+
<label for="<%= option.value %>"><%= option.label %></label>
20+
</div>
21+
<% }) %>
22+
</div>
23+
<% } else if (field.type === 'select') { %>
24+
<select>
25+
<% (field.options || []).forEach(option => { %>
26+
<option value="<%= option.value %>"><%= option.label %></option>
27+
<% }) %>
28+
</select>
1429
<% } else { %>
1530
<input type="<%= field.type %>" placeholder="<%= field.placeholder || '' %>">
1631
<% } %>

frontend/public/scripts.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,38 +92,45 @@ function back() {
9292
document.getElementById('create')?.classList.add('hidden');
9393
};
9494

95+
function saveChange(key, value) {
96+
localStorage.setItem(key, value);
97+
document.querySelector('.fixed2').classList.add('visible');
98+
setTimeout(() => {
99+
document.querySelector('.fixed2').classList.remove('visible');
100+
}, 2000);
101+
};
102+
95103
document.querySelectorAll('.inputField').forEach(field => {
96104
field.querySelectorAll('input, textarea').forEach(input => {
97105
input.addEventListener('keydown', function (event) {
98106
if (event.key === 'Enter') {
99107
event.preventDefault();
100108
next();
101109
};
102-
localStorage.setItem(field.id, input.value);
103-
document.querySelector('.fixed2').classList.add('visible');
104-
setTimeout(() => {
105-
document.querySelector('.fixed2').classList.remove('visible');
106-
}, 2000);
110+
saveChange(field.id, input.value);
107111
});
108112
});
109113
field.querySelectorAll('.checkbox').forEach(checkbox => {
110114
checkbox.addEventListener('click', function () {
111115
checkbox.classList.toggle('checked');
112116
const input = field.querySelector('input[type="checkbox"]');
113117
input.checked = !input.checked;
114-
localStorage.setItem(field.id, input.checked);
115-
document.querySelector('.fixed2').classList.add('visible');
116-
setTimeout(() => {
117-
document.querySelector('.fixed2').classList.remove('visible');
118-
}, 2000);
118+
saveChange(field.id, input.checked);
119+
});
120+
});
121+
field.querySelectorAll('.radioOption').forEach(radio => {
122+
radio.addEventListener('click', function () {
123+
field.querySelectorAll('.radioOption input[type="radio"]').forEach(r => r.checked = false);
124+
const input = radio.querySelector('input[type="radio"]');
125+
input.checked = true;
126+
saveChange(field.id, input.value);
119127
});
120128
});
121129
});
122130

123131
document.addEventListener('keydown', function (event) {
124132
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
125133
event.preventDefault();
126-
console.log('Step:', step);
127134
if (step === 0) {
128135
start();
129136
} else {

frontend/public/styles.css

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,21 @@ code {
9595
}
9696

9797
input,
98-
textarea {
98+
textarea,
99+
select {
99100
border: none;
100101
width: -webkit-fill-available;
101102
max-width: 500px;
102103
min-height: 45px;
103104
background: transparent;
104105
border-bottom: 1px solid #ffffff;
105106
outline: none;
107+
border-radius: 1px;
106108
}
107109

108110
input.hidden,
109-
textarea.hidden {
111+
textarea.hidden,
112+
select.hidden {
110113
display: none;
111114
}
112115

@@ -137,6 +140,42 @@ textarea {
137140
color: #161616;
138141
}
139142

143+
select {
144+
font-size: 15px;
145+
146+
option {
147+
background: #161616;
148+
color: #ffffff;
149+
}
150+
}
151+
152+
input[type="radio"] {
153+
height: 20px;
154+
min-height: unset;
155+
width: 20px;
156+
appearance: none;
157+
border: 1.5px solid #ffffff;
158+
border-radius: 100%;
159+
transition: 0.25s;
160+
}
161+
162+
input[type="radio"]:checked {
163+
background: #ffffff;
164+
transition: 0.25s;
165+
}
166+
167+
.radioOptions {
168+
display: flex;
169+
flex-direction: column;
170+
gap: 7.5px;
171+
172+
.radioOption {
173+
display: flex;
174+
align-items: center;
175+
gap: 5px;
176+
}
177+
}
178+
140179
main {
141180
display: flex;
142181
padding: min(100px, 10vh) 0;

0 commit comments

Comments
 (0)