Skip to content

Commit c4e0070

Browse files
authored
Feat: added support for strapi native API response (#10)
1 parent ba02f4e commit c4e0070

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

admin/src/components/Input/index.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,25 @@ const Tags = ({
9494
const inputValue = (props.value && props.value.trim().toLowerCase()) || "";
9595
const inputLength = inputValue.length;
9696

97-
let s = suggestions;
98-
99-
if (suggestions.length <= 0) {
97+
let s = suggestions.data ? suggestions.data : suggestions;
98+
if (suggestions <= 0) {
10099
getSuggestions();
101100
}
102101

103102
if (inputLength > 0) {
104-
s = suggestions.filter((state) => {
105-
return state.name.toLowerCase().slice(0, inputLength) === inputValue;
106-
});
103+
s = s.map((state) => {
104+
const suggestionName = state.attributes
105+
? state.attributes.name.toLowerCase()
106+
: state.name.toLowerCase();
107+
108+
if (suggestionName.slice(0, inputLength) === inputValue) {
109+
return {
110+
id: state.id,
111+
name: suggestionName,
112+
};
113+
}
114+
return null
115+
}).filter((ele) => ele !== null || ele != undefined);
107116
}
108117

109118
return (
@@ -130,15 +139,17 @@ const Tags = ({
130139
// GenericInput calls formatMessage and returns a string for the error
131140
error={error}
132141
hint={description && formatMessage(description)}
133-
required={required}>
142+
required={required}
143+
>
134144
<Flex
135145
direction="column"
136146
alignItems="stretch"
137147
gap={1}
138148
style={{
139149
position: `relative`,
140150
}}
141-
ref={inputEle}>
151+
ref={inputEle}
152+
>
142153
<FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>
143154
<Flex direction="column">
144155
<TagsInput

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-tagsinput",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Tagsinput plugin for your strapi project",
55
"strapi": {
66
"name": "tagsinput",

0 commit comments

Comments
 (0)