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

Unable to assign a placeholder for the search field #3362

Closed
maxwellj opened this issue May 14, 2015 · 13 comments
Closed

Unable to assign a placeholder for the search field #3362

maxwellj opened this issue May 14, 2015 · 13 comments

Comments

@maxwellj
Copy link

There is a option to add a placeholder for the select field but not for the search field.
It would be nice to be able to have a option to add a placeholder for the 'search' input field.

@chivorotkiv
Copy link

+1.

Btw. While it's not implemented I'm using following workaround:

selectElement.on('select2-open', function() {
    $('.select2-input').attr('placeholder', 'Start typing to find');
});
selectElement.on("select2-close", function() {
    $('.select2-input').attr('placeholder', null);
});

@KevP
Copy link

KevP commented Nov 10, 2015

+1

In v4.0 I had to use:

$("#my_dropdown").on("select2:open", function() {
    $(".select2-search__field").attr("placeholder", "Search...");
});
$("#my_dropdown").on("select2:close", function() {
    $(".select2-search__field").attr("placeholder", null);
});

@caseahr
Copy link

caseahr commented Mar 10, 2016

The reason this would be quite useful is that if I am filtering the list on multiple properties (e.g., name OR phone number OR email) I could add a placeholder to help the user -- "Search by customer name, phone number, or email"

@orioljd
Copy link

orioljd commented Aug 2, 2016

@KevP I used your solution but if I had a multiple select too the text "S" of "Search..." appears on it

I solved it with (your solution fixed):

$("#my_dropdown").on("select2:open", function() {
    $(".select2-search--dropdown .select2-search__field").attr("placeholder", "Search...");
});
$("#my_dropdown").on("select2:close", function() {
    $(".select2-search--dropdown .select2-search__field").attr("placeholder", null);
});

@dylankerr-bis
Copy link

There seems to be an un-documented option (at least in version 3.5.4) called searchInputPlaceholder that provides this functionality.

@seltix5
Copy link

seltix5 commented Jul 14, 2017

The option searchInputPlaceholder no longer work on the current version :(

@martinkrcho
Copy link

martinkrcho commented Aug 17, 2017

Is there a plan to put this option back in? It would be handy.

@andreivictor
Copy link

andreivictor commented Oct 8, 2017

I've created a small extension in order to implement 'searchInputPlaceholder' option.
The code and demo is available here:
http://jsfiddle.net/pagr61bm/

@alexweissman
Copy link
Contributor

This is great! Would you be willing to set this up in a dedicated repo?

@andreivictor
Copy link

@alexweissman, I've created a small repository for this extension:
https://github.com/andreivictor/select2-searchInputPlaceholder

@alexweissman
Copy link
Contributor

Nice! Looks good. You should also be able to use the new "topics" feature to label your repo with "select2" as well.

@KyleMit
Copy link

KyleMit commented Dec 15, 2017

@KevP / @orioljd - Two Notes

  1. This will set the placeholder for all controls as soon as one is opened. Probably fine, but it's an odd place to add that kind of initialization for everything inside of the handler for a specific one.

  2. More importantly this breaks in most versions of IE if you need to support them per IE breaks when using a multiple select with a placeholder #3300 & 4.0.0-rc2 Selecting nothing with a multiselect placeholder prevents dropdown from closing in IE. #3257

@select2 select2 deleted a comment from Mattomanka Dec 15, 2017
@select2 select2 deleted a comment from librisius Dec 15, 2017
@select2 select2 deleted a comment from vinothjayaraman Dec 15, 2017
@select2 select2 deleted a comment from hoffmanilya Dec 15, 2017
@select2 select2 deleted a comment from StephaneJuban Dec 15, 2017
@select2 select2 deleted a comment from FutureKode Dec 15, 2017
@select2 select2 deleted a comment from nistic Dec 15, 2017
@select2 select2 deleted a comment from ohenrik Dec 15, 2017
@select2 select2 deleted a comment Dec 15, 2017
@select2 select2 deleted a comment from npapazian Dec 15, 2017
@select2 select2 deleted a comment from austencm Dec 15, 2017
@select2 select2 deleted a comment from kpschuck Dec 15, 2017
@select2 select2 deleted a comment from ttucker Dec 15, 2017
@select2 select2 deleted a comment from njakobsen Dec 15, 2017
@pedrofurtado
Copy link
Contributor

We don't have immediate plans to provide this. We are focused to fix some major UI bugs (that are majority of issues and PR's). But if you open a PR with unit tests, I will be glad to review and approve if everything is ok 👍

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

No branches or pull requests