diff --git a/js/map.js b/js/map.js index 29869249..f50e88b6 100644 --- a/js/map.js +++ b/js/map.js @@ -254,7 +254,7 @@ // Find address field based on its name attribute. Auto search inside groups when needed. findAddressField: function ( fieldName ) { - const selector = `input[name="${ fieldName }"], select[name="${ fieldName }"]`; + let selector = `input[name="${ fieldName }"], select[name="${ fieldName }"]`; // Not in a group. let $address = $( selector ); @@ -262,14 +262,18 @@ return $address; } - // If map and address is inside a cloneable group. - $address = this.$container.closest( '.rwmb-group-clone' ).find( selector ); - if ( $address.length ) { - return $address; + let $groupWrapper = this.$container.closest( '.rwmb-group-clone' ); + if ( ! $groupWrapper.length ) { + $groupWrapper = this.$container.closest( '.rwmb-group-wrapper' ); + } + + if ( ! $groupWrapper.length ) { + return null; } - // If map and address is inside a non-cloneable group. - $address = this.$container.closest( '.rwmb-group-wrapper' ).find( selector ); + selector = `input[name*="${ fieldName }"], select[name*="${ fieldName }"]`; + + $address = $groupWrapper.find( selector ); if ( $address.length ) { return $address; } diff --git a/js/osm.js b/js/osm.js index cd79916f..ef56524d 100644 --- a/js/osm.js +++ b/js/osm.js @@ -248,18 +248,18 @@ return $address; } - let groupWrapper = this.$container.closest( '.rwmb-group-clone' ); - if ( ! groupWrapper.length ) { - groupWrapper = this.$container.closest( '.rwmb-group-wrapper' ); + let $groupWrapper = this.$container.closest( '.rwmb-group-clone' ); + if ( ! $groupWrapper.length ) { + $groupWrapper = this.$container.closest( '.rwmb-group-wrapper' ); } - if ( ! groupWrapper.length ) { + if ( ! $groupWrapper.length ) { return null; } selector = `input[name*="${ fieldName }"], select[name*="${ fieldName }"]`; - $address = groupWrapper.find( selector ); + $address = $groupWrapper.find( selector ); if ( $address.length ) { return $address; }