Choices: Dynamic placeholders for Multi-select no longer working in 9.x

Created on 25 Nov 2019  路  6Comments  路  Source: Choices-js/Choices

Describe the bug
In all versions <= 8.0.0, placeholders would show up for multiple select dropdown configurations. This is no longer working in the 9.x branch.

To Reproduce
Steps to reproduce the behavior:

  1. Add a new multi-select with no initial options.
  2. Use the following code to add placeholder.
<select id="myselect"></select>
new Choices(document.getElementById('myselect'), {
  placeholderValue: 'This should be a placeholder'
});

Expected behavior
You should see the placeholder.

Screenshots
Will provide if necessary but this is pretty easy to reproduce.

Desktop (please complete the following information):

  • MacOS, Chrome
bug

All 6 comments

I am also hitting this bug

Hey - so I actually removed this functionality in the 9.0.0 release (https://github.com/jshjohnson/Choices/pull/731) but have clearly forgotten to update the documentation 馃う鈥嶁檪For versions >=9.x, placeholderValue will only apply to text elements. The reason for removing it was the added complexity of supporting it.

This can be done by just adding a "placeholder" attribute on the input element that is part of the multi-select. This would normally be done via configurations, but the issue the current branch has it is does not default to the placeholder configurations if the select element does not have a "default" select option. The following pull request fixes this issue with minimal changes.

https://github.com/jshjohnson/Choices/pull/788

@jshjohnson then what is the current way to add a placeholder to multiselect? searchPlaceholderValue does not work either.

@travist thanks. I've ended with dumb'n'brute solution (using Preact):

  useEffect(() => {
    const choices = new Choices(selectRef.current, options as IChoices.Options);

    if (restProps.multiple && choices.config.placeholderValue) {
      ((choices as any).input as HTMLInputElement).placeholder = choices.config.placeholderValue;
    }
  }, []);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfonsoar picture alfonsoar  路  4Comments

sebastien-roch picture sebastien-roch  路  3Comments

zslabs picture zslabs  路  6Comments

kjugi picture kjugi  路  3Comments

ryanbuening picture ryanbuening  路  4Comments