Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to limit the search result displayed in the search bar when searching multiple properties? #332

Open
muppetdance opened this issue Mar 30, 2024 · 0 comments

Comments

@muppetdance
Copy link

I want to search multiple properties in my geoJSON, namely 'name' and 'address'. I can achieve this using

layer.feature.properties.searchTerm =layer.feature.properties.name + layer.feature.properties.address;

in the onEachFeature function, and then in the controlSearch,

var controlSearch = new L.Control.Search({ position:'topright', layer: featuresLayer, propertyName: 'searchTerm', initial: false, marker: false, minLength: 3, zoom: 16 });

The problem is that both the name and address properties appear in the results and the search bar when a result is clicked. Is there a way to restrict the text in the search bar to just the name property?

If I add:

buildTip: customTip,

to the controlSearch and create the following function:

function customTip(text,val) { return '<a href="#">'+text+'. adjust</a>'; }

then the search results are restricted to displaying just the name (though I can't work out why this might be the case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant