@@ -60,6 +60,20 @@ $(document).ready(function () {
6060 populateAdvancedSearchFormFromSession ( ) ;
6161 populateSimpleSearch ( ) ;
6262
63+ $ ( '#form-container' ) . on ( 'change' , '[id^=entry-][id$=-metadata_tag]' , function ( ) {
64+ var id = $ ( this ) . attr ( 'id' ) ;
65+ var idx = id . split ( '-' ) [ 1 ] ; // Get the index from the id
66+ updateConditionOptions ( idx , $ ( this ) . val ( ) ) ;
67+ console . log ( $ ( this ) . val ( ) ) ;
68+ } ) ;
69+
70+ // Delegated change event for condition
71+ $ ( '#form-container' ) . on ( 'change' , '[id^=entry-][id$=-condition]' , function ( ) {
72+ var id = $ ( this ) . attr ( 'id' ) ;
73+ var idx = id . split ( '-' ) [ 1 ] ; // Get the index from the id
74+ updateValueField ( idx , $ ( this ) . val ( ) ) ;
75+ } ) ;
76+
6377 $ ( '#addRow' ) . on ( 'click' , function ( ) {
6478 // Increment the row index when button is clicked
6579 rowIdx ++ ;
@@ -117,17 +131,6 @@ $(document).ready(function () {
117131 $ ( '#removeRow' + rowIdx ) . on ( 'click' , function ( ) {
118132 $ ( this ) . closest ( 'div.row' ) . remove ( ) ;
119133 } ) ;
120-
121- // Bind the change event for the metadata tag select field of the new row
122- $ ( '#entry-' + rowIdx + '-metadata_tag' ) . on ( "change" , function ( ) {
123- updateConditionOptions ( rowIdx , $ ( this ) . val ( ) ) ;
124- console . log ( $ ( this ) . val ( ) ) ;
125- } ) ;
126-
127- // Set the initial event listener for the choice select field in the first row
128- $ ( '#entry-' + rowIdx + '-condition' ) . on ( "change" , function ( ) {
129- updateValueField ( rowIdx , $ ( this ) . val ( ) ) ;
130- } ) ;
131134
132135 //entry-${rowIdx}-metadata_tag
133136 updateConditionOptions ( rowIdx , $ ( '#entry-' + rowIdx + '-metadata_tag' ) . val ( ) ) ;
@@ -139,16 +142,6 @@ $(document).ready(function () {
139142
140143 } ) ;
141144
142- // Set the initial event listener for the metadata tag select field in the first row
143- $ ( '#entry-0-metadata_tag' ) . on ( "change" , function ( ) {
144- updateConditionOptions ( 0 , $ ( this ) . val ( ) ) ;
145- } ) ;
146-
147- // Set the initial event listener for the choice select field in the first row
148- $ ( '#entry-0-condition' ) . on ( "change" , function ( ) {
149- updateValueField ( 0 , $ ( this ) . val ( ) ) ;
150- } ) ;
151-
152145 //advanced Search handler
153146 $ ( "#advancedSearchForm" ) . one ( "submit" , validateAdvancedSearch ) ;
154147
@@ -272,7 +265,7 @@ function addRowWithValues(metadataTag, condition, value, weight) {
272265 <button id="removeRow${ rowIdx } " type="button" class="btn btn-danger">Remove</button>
273266 </div>
274267 </div>
275- ` ) ;
268+ `) ;
276269
277270
278271 $ ( "#entry-" + rowIdx + "-metadata_tag" ) . append ( options ) ;
@@ -285,15 +278,7 @@ function addRowWithValues(metadataTag, condition, value, weight) {
285278 $ ( '#removeRow' + rowIdx ) . on ( 'click' , function ( ) {
286279 $ ( this ) . closest ( 'div.row' ) . remove ( ) ;
287280 } ) ;
288- // Bind the change event for the metadata tag select field of the new row
289- $ ( '#entry-' + rowIdx + '-metadata_tag' ) . on ( "change" , function ( ) {
290- updateConditionOptions ( rowIdx , $ ( this ) . val ( ) ) ;
291- console . log ( $ ( this ) . val ( ) ) ;
292- } ) ;
293- // Set the initial event listener for the choice select field in the first row
294- $ ( '#entry-' + rowIdx + '-condition' ) . on ( "change" , function ( ) {
295- updateValueField ( rowIdx , $ ( this ) . val ( ) ) ;
296- } ) ;
281+
297282 initializeSelect2 ( "entry-" + rowIdx + "-metadata_tag" ) ;
298283 updateConditionOptions ( rowIdx , $ ( "#entry-" + rowIdx + "-metadata_tag" ) . val ( ) ) ;
299284 updateValueField ( rowIdx , $ ( "#entry-" + rowIdx + "-condition" ) . val ( ) ) ;
0 commit comments