@@ -19,6 +19,7 @@ export interface FormKitPrimeAutoCompleteProps {
1919 minLength? : AutoCompleteProps [' minLength' ]
2020 placeholder? : AutoCompleteProps [' placeholder' ]
2121 fluid? : AutoCompleteProps [' fluid' ]
22+ separators? : string [] | []
2223}
2324
2425const props = defineProps ({
@@ -34,6 +35,12 @@ const suggestions = ref(['', {}])
3435suggestions .value = []
3536const loading = ref (false )
3637
38+ /**
39+ * Searches for suggestions based on the input query.
40+ * If options and optionLabel are provided, it filters the options.
41+ * Otherwise, it calls the complete function from the context to fetch suggestions.
42+ * @param event - The AutoCompleteCompleteEvent containing the query.
43+ */
3744async function search(event : AutoCompleteCompleteEvent ) {
3845 if (props .context ?.options && props .context ?.optionLabel ) {
3946 suggestions .value = props .context .options .filter ((option ) => {
@@ -54,6 +61,38 @@ async function search(event: AutoCompleteCompleteEvent) {
5461 }
5562 }
5663}
64+
65+ /**
66+ * Handles paste event to transform a string separated by any of the provided separators into multiple items.
67+ * @param event - The paste event from the input.
68+ */
69+ function handlePaste(event : ClipboardEvent ) {
70+ if (! props .context ?.multiple )
71+ return
72+ const clipboardData = event .clipboardData
73+ if (! clipboardData )
74+ return
75+ const pastedText = clipboardData .getData (' text' )
76+ const separators = Array .isArray (props .context ?.separators ) && props .context .separators .length > 0
77+ ? props .context .separators
78+ : [' ,' ]
79+ // Create a regex to split by any separator, escaping special regex characters
80+ const regex = new RegExp (` [${separators .map (s => s .replace (/ [-/\\ ^$*+?. ()|[\] {}] / g , ' \\ $&' )).join (' ' )}] ` )
81+ if (pastedText && regex .test (pastedText )) {
82+ event .preventDefault ()
83+ const items = pastedText
84+ .split (regex )
85+ .map (item => item .trim ())
86+ .filter (item => item .length > 0 )
87+ if (Array .isArray (props .context ._value )) {
88+ props .context ._value .push (... items )
89+ }
90+ else {
91+ props .context ._value = items
92+ }
93+ props .context ?.node ?.input ?.(props .context ?._value )
94+ }
95+ }
5796 </script >
5897
5998<template >
@@ -85,6 +124,7 @@ async function search(event: AutoCompleteCompleteEvent) {
85124 @complete =" search"
86125 @change =" handleInput"
87126 @blur =" handleBlur"
127+ @paste =" handlePaste"
88128 >
89129 <template v-for =" slotName in validSlotNames " :key =" slotName " #[slotName ]=" slotProps " >
90130 <component :is =" context?.slots[slotName]" v-bind =" { ...context, ...slotProps }" />
0 commit comments