33 < input type ="hidden " name ="elements[] " value ="[[id]] ">
44 < input type ="hidden " name ="[[id]]-type " value ="[[type]] ">
55 < input type ="hidden " name ="[[id]]-parameter " value ="[[parameter]] ">
6- < input type ="hidden " name ="[[parameter]]-numberOfVersions " value ="[[numberOfVersions]] ">
76
87 < b > [[name]]</ b > (< i > [[parameter]]</ i > )
9- {{FOR i;0;[[numberOfVersions]]}}
10- < div class ="input-group " style ="margin-bottom: 0.3em; ">
11- < span class ="input-group-addon text-bold " style ="background-color: #f7f7f7; "> Version [[Util::increment([[i]])]]</ span >
12- < input name ="[[parameter]]-version-[[i]] " type ="text " class ="form-control " placeholder ="Branch for version [[Util::increment([[i]])]] "
13- {{IF Util::issetElementOfArray([[copy]],[[i]])}} value ="[[Util::getElementFromArray([[copy]],[[i]])]] "{{ENDIF}}
14- {{IF !Util::issetElementOfArray([[copy]],[[i]]) && Util::issetElementOfArray(explode( ',',[[default]]),[[i]])}} value="[[Util::getElementFromArray([[explode(',',[[default]])]],[[i]])]] "{{ENDIF}} >
15- </ div >
16- {{ENDFOR}}
8+ < div class ="input-group ">
9+ < span class ="input-group-addon text-bold " style ="background-color: #f7f7f7; "> Number of Versions</ span >
10+ < input id ="numberOfVersionsInput " name ="[[parameter]]-numberOfVersions " type ="number " class ="form-control " placeholder ="Number of versions to compare " min ="0 ">
11+ </ div >
12+ < div id ="versionInputsContainer "> </ div >
13+
14+ < script >
15+ const copy = JSON . parse ( '[[json_encode([[copy]])]]' ) ;
16+ const initialNumberOfVersions = copy . length ;
17+
18+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
19+ const numberOfVersionsInput = document . getElementById ( 'numberOfVersionsInput' ) ;
20+ const versionInputsContainer = document . getElementById ( 'versionInputsContainer' ) ;
21+
22+ // Set the initial value for the number of versions input based on the copy array length
23+ numberOfVersionsInput . value = initialNumberOfVersions ;
24+
25+ function createVersionInput ( index , value = '' ) {
26+ const div = document . createElement ( 'div' ) ;
27+ div . classList . add ( 'input-group' ) ;
28+ div . style . marginTop = '0.3em' ;
29+
30+ const span = document . createElement ( 'span' ) ;
31+ span . classList . add ( 'input-group-addon' , 'text-bold' ) ;
32+ span . style . backgroundColor = '#f7f7f7' ;
33+ span . textContent = `Version ${ index + 1 } ` ;
34+
35+ const input = document . createElement ( 'input' ) ;
36+ input . name = `[[parameter]]-version-${ index } ` ;
37+ input . type = 'text' ;
38+ input . classList . add ( 'form-control' ) ;
39+ input . placeholder = `Branch for version ${ index + 1 } ` ;
40+ if ( value ) {
41+ input . value = value ;
42+ }
43+
44+ div . appendChild ( span ) ;
45+ div . appendChild ( input ) ;
46+ return div ;
47+ }
48+
49+ function populateInitialInputs ( ) {
50+ for ( let i = 0 ; i < initialNumberOfVersions ; i ++ ) {
51+ const value = copy [ i ] !== undefined ? copy [ i ] : '' ;
52+ const versionInput = createVersionInput ( i , value ) ;
53+ versionInputsContainer . appendChild ( versionInput ) ;
54+ }
55+ }
56+
57+ function updateVersionInputs ( ) {
58+ const currentInputs = versionInputsContainer . querySelectorAll ( 'input' ) ;
59+ const numberOfVersions = parseInt ( numberOfVersionsInput . value , 10 ) || 0 ;
60+
61+ if ( numberOfVersions > currentInputs . length ) {
62+ // Add new inputs
63+ for ( let i = currentInputs . length ; i < numberOfVersions ; i ++ ) {
64+ const versionInput = createVersionInput ( i , '' ) ;
65+ versionInputsContainer . appendChild ( versionInput ) ;
66+ }
67+ } else if ( numberOfVersions < currentInputs . length ) {
68+ // Remove excess inputs
69+ for ( let i = currentInputs . length - 1 ; i >= numberOfVersions ; i -- ) {
70+ versionInputsContainer . removeChild ( currentInputs [ i ] . parentElement ) ;
71+ }
72+ }
73+ }
74+
75+ // Populate inputs based on the initial number of versions and the copy array
76+ populateInitialInputs ( ) ;
77+
78+ // Update the inputs whenever the number of versions changes
79+ numberOfVersionsInput . addEventListener ( 'input' , updateVersionInputs ) ;
80+ } ) ;
81+ </ script >
82+
83+
1784
1885 </ div >
1986</ div >
0 commit comments