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

Ability to add aliases to labels for searching #5

Closed
yahyaerturan opened this issue Feb 4, 2021 · 8 comments
Closed

Ability to add aliases to labels for searching #5

yahyaerturan opened this issue Feb 4, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@yahyaerturan
Copy link

Great plugin, thank you.

It would be really nice to add aliases to labels for searching. I am using this library instead of bootstrap-select with BS5.

    <option value="27" data-aliases="turkey,middle east">Istanbul</option>
    <option value="43" data-aliases="england,united kingdom,europe">London</option>

This is the final html I proposed. We should be able to find "London" option when we type england or europe for example.

@sa-si-dev
Copy link
Owner

It is an interesting feature to have.

I will work on it in the future release.

Thanks for your suggesion.

@sa-si-dev sa-si-dev self-assigned this Feb 4, 2021
@sa-si-dev sa-si-dev added the enhancement New feature or request label Feb 4, 2021
@sa-si-dev sa-si-dev removed their assignment Feb 4, 2021
@frg
Copy link

frg commented Feb 4, 2021

@yahyaerturan This functionality has been added in #7 however since this plugin does not deal with importing the options from the DOM directly you'll have to query and parse the terms manually.

const select = document.querySelector("#select");
const options = Array.prototype.slice.call(select.options)
    .map(x => {
        return {
            label: x.text,
            value: x.value,
            terms: x.getAttribute("data-aliases").split(","),
        }
    });

@yahyaerturan
Copy link
Author

If I get it right, this will result in a second mapping of json data as we set options by json when initializing? The html I wrote here as a sample of final output. Will this be done after initializing virtual select? More generic solution might be defining searchable json keys when initialising and leave the rest to the backend.

@frg
Copy link

frg commented Feb 5, 2021

The html I wrote here as a sample of final output.

This plugin does not generate a select HTML element which means it also does not generate option HTML elements.

You would initialize the plugin as shown below

VirtualSelect.init({
  ele: '#sample-select',
  options: [
    { label: 'Options 1', value: '1', terms: ['london', 'england'] },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
  ],
});

@yahyaerturan
Copy link
Author

👍 Looks great. Thank you.. Next release will be a loaded gun :)

@sa-si-dev
Copy link
Owner

@yahyaerturan This functionality has been added in #7 however since this plugin does not deal with importing the options from the DOM directly you'll have to query and parse the terms manually.

const select = document.querySelector("#select");
const options = Array.prototype.slice.call(select.options)
    .map(x => {
        return {
            label: x.text,
            value: x.value,
            terms: x.getAttribute("data-aliases").split(","),
        }
    });

@frg, it is not recommanded to read data from DOM element. The main problem, this plugin trying to solve is, reduce the no.of DOM element.

It is good to handle data in JS object for better performance.

@frg
Copy link

frg commented Feb 5, 2021

I agree, if I understood @yahyaerturan correctly by his example he already has a select element on his page which he's like to convert to using the plugin. I could have misunderstood.

@sa-si-dev
Copy link
Owner

Great plugin, thank you.

It would be really nice to add aliases to labels for searching. I am using this library instead of bootstrap-select with BS5.

    <option value="27" data-aliases="turkey,middle east">Istanbul</option>
    <option value="43" data-aliases="england,united kingdom,europe">London</option>

This is the final html I proposed. We should be able to find "London" option when we type england or europe for example.

@yahyaerturan as you requested, we have implemented the feature to allow using alias for searching.

This feature is available in the release v.1.0.3 (more details)

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

No branches or pull requests

3 participants