Skip to content

Commit

Permalink
Merge pull request #1623 from wpmetabox/feat-osm-inside-group
Browse files Browse the repository at this point in the history
feat: osm autocomplete inside group
  • Loading branch information
rilwis authored Dec 13, 2024
2 parents 390e36b + a7130ba commit a7353cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,26 @@

// 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 );
if ( $address.length ) {
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;
}
Expand Down
18 changes: 11 additions & 7 deletions js/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,26 @@

// 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 );
if ( $address.length ) {
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;
}
Expand Down

0 comments on commit a7353cf

Please sign in to comment.