select2-component icon indicating copy to clipboard operation
select2-component copied to clipboard

Allow custom/new value

Open utillity opened this issue 5 years ago • 6 comments

Hi, is it possible to allow the user to keep his search-phrase as a new value, if it is not available yet? thanks

utillity avatar Dec 13 '20 16:12 utillity

You mean in search input, you press Enter, the current search text is added as a new option?

plantain-00 avatar Dec 14 '20 07:12 plantain-00

That or that the text is kept for further processing upon pressing the save button

lg Tilli


From: York Yao [email protected] Sent: Monday, December 14, 2020 8:18:04 AM To: plantain-00/select2-component [email protected] Cc: Tilfried Weissenberger [email protected]; Author [email protected] Subject: Re: [plantain-00/select2-component] Allow custom/new value (#42)

You mean in search input, you press Enter, the current search text is added as a new option?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/plantain-00/select2-component/issues/42#issuecomment-744228335, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABKK55V3AZAYGRKCZDXWI73SUW32ZANCNFSM4UZTWZDA.

utillity avatar Dec 14 '20 07:12 utillity

You can try to listen search event and store search text, when you click you save button, just add the search text as a new option.

plantain-00 avatar Dec 14 '20 09:12 plantain-00

thanks! how can I have it stay in the textbox?

utillity avatar Dec 14 '20 09:12 utillity

You can try to enable keepSearchText property.

plantain-00 avatar Dec 14 '20 10:12 plantain-00

keepSearchText will not do the job. If I intercept keydown and check for ev.code === "Enter" and add a new item and set the value etc. it works, but then if a user selects an existing item it won't. So I also need to listen to the update event. But then right after the keydown event does it's job, a "random" list item is being chosen and the update event is fired, overwriting the manual selection

utillity avatar Dec 15 '20 15:12 utillity