@@ -26,7 +26,7 @@ const dropdownConfig = {
26
26
fields : [
27
27
{ id : 'id' , label : 'Dropdown ID' , type : 'text' , placeholder : 'Enter ID' } ,
28
28
{ id : 'dropdownValues' , label : 'Dropdown Options' , type : 'text' , placeholder : 'Comma-separated values' } ,
29
- { id : 'font' , label : 'Font' , type : 'select' , options : [ 'Arial ' , 'Verdana ' , 'Times New Roman ' ] } ,
29
+ { id : 'font' , label : 'Font' , type : 'select' , options : [ 'Courier ' , 'Helvetica ' , 'TimesRoman ' ] } ,
30
30
{ id : 'fontSize' , label : 'Font Size' , type : 'number' , value : '12' } ,
31
31
{ id : 'backgroundPalette' , label : 'Background Color' , type : 'color' , value : '#ffffff' } ,
32
32
{ id : 'textPalette' , label : 'Text Color' , type : 'color' , value : '#000000' }
@@ -119,7 +119,7 @@ document.querySelector('input[name=pdf-upload]').addEventListener('change', asyn
119
119
120
120
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
121
121
document . querySelectorAll ( '.show-on-file-selected' ) . forEach ( ( el ) => {
122
- // el.style.cssText = 'display:none !important';
122
+ el . style . cssText = 'display:none !important' ;
123
123
} ) ;
124
124
document . addEventListener ( 'keydown' , ( e ) => {
125
125
if ( e . key === 'Delete' ) {
@@ -160,31 +160,54 @@ window.createForm = (configString) => {
160
160
input . appendChild ( option ) ;
161
161
} ) ;
162
162
} else if ( field . type === 'color' ) {
163
- input = document . createElement ( 'input' ) ;
163
+ // Create label
164
+ const label = document . createElement ( 'label' ) ;
165
+ label . classList . add ( 'form-check-label' ) ;
166
+ label . setAttribute ( 'for' , field . id ) ;
167
+ label . textContent = field . label ;
168
+
169
+ // Create color input
170
+ const input = document . createElement ( 'input' ) ;
164
171
input . classList . add ( 'palette' ) ;
165
172
input . setAttribute ( 'type' , 'color' ) ;
166
173
input . setAttribute ( 'id' , field . id ) ;
167
174
input . setAttribute ( 'name' , field . id ) ;
168
175
input . setAttribute ( 'value' , field . value || '#000000' ) ;
169
176
177
+ // Create color picker button
170
178
const paletteContainer = document . createElement ( 'button' ) ;
171
179
paletteContainer . classList . add ( 'colour-picker' , 'btn-primary' ) ;
172
180
paletteContainer . setAttribute ( 'id' , `${ field . id } Container` ) ;
173
181
paletteContainer . setAttribute ( 'th:title' , '#{redact.colourPicker}' ) ;
174
182
183
+ // Create label for color picker
175
184
const paletteLabel = document . createElement ( 'label' ) ;
176
185
paletteLabel . setAttribute ( 'id' , `${ field . id } Label` ) ;
177
186
paletteLabel . setAttribute ( 'for' , field . id ) ;
178
187
paletteLabel . classList . add ( 'material-symbols-rounded' , 'palette-color' , 'text-center' ) ;
179
188
paletteLabel . style . setProperty ( '--palette-color' , field . value || '#000000' ) ;
180
189
paletteLabel . textContent = 'palette' ;
181
190
191
+ // Append input to label
182
192
paletteLabel . appendChild ( input ) ;
183
193
paletteContainer . appendChild ( paletteLabel ) ;
184
- formContainer . appendChild ( label ) ;
185
- formContainer . appendChild ( paletteContainer ) ;
194
+
195
+ // Find or create the color group flex container
196
+ let colorGroup = formContainer . querySelector ( '.color-group' ) ;
197
+ if ( ! colorGroup ) {
198
+ colorGroup = document . createElement ( 'div' ) ;
199
+ colorGroup . classList . add ( 'color-group' ) ;
200
+ colorGroup . style . display = 'flex' ;
201
+ colorGroup . style . gap = '10px' ; // Space between color inputs
202
+ colorGroup . style . marginTop = '10px' ; // Space above first color input
203
+ formContainer . appendChild ( colorGroup ) ;
204
+ }
205
+ colorGroup . appendChild ( label ) ;
206
+ colorGroup . appendChild ( paletteContainer ) ;
207
+
186
208
return ;
187
- } else {
209
+ }
210
+ else {
188
211
input = document . createElement ( 'input' ) ;
189
212
input . classList . add ( 'form-control' ) ;
190
213
input . setAttribute ( 'type' , field . type ) ;
@@ -225,7 +248,6 @@ function validateUniqueId(id) {
225
248
function attachDynamicListeners ( fields ) {
226
249
fields . forEach ( field => {
227
250
document . addEventListener ( "change" , function ( event ) {
228
- console . log ( "hit" ) ;
229
251
if ( event . target && event . target . id === field . id ) {
230
252
if ( field . type === 'color' ) {
231
253
document . getElementById ( `${ field . id } Label` ) . style . setProperty ( '--palette-color' , event . target . value ) ;
@@ -235,27 +257,32 @@ function attachDynamicListeners(fields) {
235
257
if ( field . type === 'color' ) {
236
258
if ( field . id . toLowerCase ( ) . includes ( 'background' ) ) {
237
259
targetElement . style . background = event . target . value ;
260
+ targetElement . setAttribute ( 'backgroundColor' , event . target . value )
238
261
} else {
239
262
targetElement . style . color = event . target . value ;
263
+ targetElement . setAttribute ( 'textColor' , event . target . value )
240
264
}
241
265
} else if ( field . id === 'fontSize' ) {
242
266
targetElement . style . fontSize = event . target . value + "px" ;
267
+ } else if ( field . id === 'font' ) {
268
+ targetElement . style . fontFamily = event . target . value ;
243
269
} else if ( field . id === 'value' ) {
244
270
targetElement . value = event . target . value ;
245
271
} else if ( field . id === 'id' ) {
246
272
targetElement . id = event . target . value ;
273
+ targetElement . name = event . target . value ;
247
274
} else if ( field . id === 'dropdownValues' ) {
248
- while ( targetElement . firstChild ) {
275
+ while ( targetElement ? .firstChild ) {
249
276
targetElement . removeChild ( targetElement . firstChild ) ;
250
277
}
251
-
252
278
const values = event . target . value . split ( ',' ) . map ( v => v . trim ( ) ) ;
253
279
values . forEach ( value => {
254
280
const option = document . createElement ( "option" ) ;
255
281
option . value = value ;
256
282
option . textContent = value ;
257
283
targetElement . appendChild ( option ) ;
258
284
} ) ;
285
+ targetElement . setAttribute ( "data-value" , values )
259
286
}
260
287
}
261
288
}
@@ -279,6 +306,8 @@ function addDraggableFromForm(config) {
279
306
element . setAttribute ( 'id' , id ) ;
280
307
element . setAttribute ( 'name' , id ) ;
281
308
element . setAttribute ( 'type' , config . type ) ;
309
+ element . style . fontFamily = 'Helvetica'
310
+ element . style . fontSize = '12' ;
282
311
element . classList . add ( 'form-input' )
283
312
284
313
if ( config . styles ) {
@@ -288,7 +317,6 @@ function addDraggableFromForm(config) {
288
317
}
289
318
290
319
DraggableUtils . addDraggableElement ( element , true ) ;
291
- showTab ( 0 ) ;
292
320
}
293
321
294
322
document . getElementById ( 'save' ) . addEventListener ( 'click' , function ( ) {
@@ -332,21 +360,14 @@ document.getElementById('save').addEventListener('click', function () {
332
360
} ) ;
333
361
} ) ;
334
362
335
- const showTab = ( index ) => {
336
- const tabs = document . querySelectorAll ( ".tab-container" ) ;
337
- tabs . forEach ( ( tab , i ) => {
338
- // tab.style.display = i === index ? "block" : "none";
339
- } ) ;
340
- }
363
+
341
364
document . addEventListener ( "DOMContentLoaded" , function ( ) {
342
- const tabs = document . querySelectorAll ( ".tab-container" ) ;
343
365
const addNewFormContainer = document . getElementById ( "addNewForm" ) ;
344
366
const formOptionsContainer = document . getElementById ( "formOptions" ) ;
345
367
function createDropdown ( ) {
346
368
const dropdown = document . createElement ( "select" ) ;
347
369
dropdown . classList . add ( "form-control" ) ;
348
370
dropdown . id = "formTypeSelector" ;
349
-
350
371
const defaultOption = document . createElement ( "option" ) ;
351
372
defaultOption . textContent = "Select Form Type" ;
352
373
defaultOption . value = "" ;
@@ -360,6 +381,9 @@ document.addEventListener("DOMContentLoaded", function () {
360
381
} ) ;
361
382
362
383
addNewFormContainer . prepend ( dropdown ) ;
384
+ dropdown . addEventListener ( 'change' , async ( event ) => {
385
+ // populateEditForm(event.target.value, { id: generateUniqueId(event.target.value) });
386
+ } )
363
387
}
364
388
365
389
window . populateEditForm = ( type , existingValues ) => {
@@ -370,16 +394,14 @@ document.addEventListener("DOMContentLoaded", function () {
370
394
const input = document . getElementById ( key ) ;
371
395
if ( input ) {
372
396
input . value = existingValues [ key ] ;
397
+ if ( input . type === "color" ) {
398
+ document . getElementById ( `${ input . id } Label` ) . style . setProperty ( '--palette-color' , existingValues [ key ] ) ;
399
+ }
373
400
}
401
+
374
402
} ) ;
375
403
376
- showTab ( 0 ) ;
377
404
}
378
405
379
- document . getElementById ( "save" ) . addEventListener ( "click" , function ( ) {
380
- showTab ( 0 ) ;
381
- } ) ;
382
-
383
406
createDropdown ( ) ;
384
- showTab ( 1 ) ;
385
407
} ) ;
0 commit comments