diff --git a/js/osm.js b/js/osm.js index 2fc27262..cd79916f 100644 --- a/js/osm.js +++ b/js/osm.js @@ -240,7 +240,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 ); @@ -248,14 +248,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; }