react-native-dropdown-picker icon indicating copy to clipboard operation
react-native-dropdown-picker copied to clipboard

How to change the Placeholder text for when Items are selected

Open parsa-j42 opened this issue 2 years ago • 7 comments

I have a DropDownPicker component with multiple={true}. I know I can use the placeholder property to change the placeholder text, But when I select an item (or more) in the dropdown, the text changes to "An item has been selected" or "(number) items have been selected".

How can I change the placeholder's text in these situations? Or is there any option, so I can keep the placeholder static, so it doesn't change when I select the items?

parsa-j42 avatar Aug 25 '22 16:08 parsa-j42

@parsa-j42 Any update on this ? In my case multiple selection is turned off. I just want to change the label after selecting an item.

vinaynarayankutty avatar Sep 06 '22 02:09 vinaynarayankutty

@vinaynarayankutty Nope.

parsa-j42 avatar Sep 06 '22 02:09 parsa-j42

you add the multipleText to your component <DropDownPicker multipleText={'some text'} />

medsabbar avatar Nov 01 '22 10:11 medsabbar

you add the multipleText to your component <DropDownPicker multipleText={'some text'} />

Nice one, but is there a way to set it as one text when only one item is picked and a second text when multiple items are picked? Example: One day has been selected when one item is selected {count} days have been selected when more than one item selected

mariusgaciu avatar Nov 14 '22 12:11 mariusgaciu

@mariusgaciu you can use variables and many ternary condition inside multipleText, using the length of value you can achieve what you want like this:

multipleText={${value.length} ${value.length == 1 ? 'day' : 'days' } has been selected}

amandaO2hess avatar Apr 12 '23 12:04 amandaO2hess

you add the multipleText to your component <DropDownPicker multipleText={'some text'} />

Nice one, but is there a way to set it as one text when only one item is picked and a second text when multiple items are picked? Example: One day has been selected when one item is selected {count} days have been selected when more than one item selected

multipleText={multiple && ${selectValue.length} ${t('selected')}} Based on the selected values length you can chain your condition I usually just show the count, and below the select component I show all the selected values if needed like so

{multiple && ( <Text style={{ fontSize: 18, fontStyle: 'italic' }}>{*${selectValue .map(v => { const item = items.find(i => i.value === v); return item ? item.label : ''; }) .join(', ')}}</Text> )}

medsabbar avatar Apr 12 '23 19:04 medsabbar

@amandaO2hess @medsabbar Than you for the solutions provided.

mariusgaciu avatar Apr 20 '23 10:04 mariusgaciu