File tree 2 files changed +35
-4
lines changed
packages/ra-core/src/form
2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,35 @@ describe('getSuggestions', () => {
110
110
] ) ;
111
111
} ) ;
112
112
113
+ it ( 'should not add createSuggestion if allowCreate is true and the current filter matches exactly the selected item' , ( ) => {
114
+ expect (
115
+ getSuggestions ( {
116
+ ...defaultOptions ,
117
+ selectedItem : { id : 1 , value : 'one' } ,
118
+ allowCreate : true ,
119
+ } ) ( 'one' )
120
+ ) . toEqual ( [
121
+ { id : 2 , value : 'two' } ,
122
+ { id : 3 , value : 'three' } ,
123
+ ] ) ;
124
+ } ) ;
125
+
126
+ it ( 'should add createSuggestion if allowCreate is true and selectedItem is an array' , ( ) => {
127
+ expect (
128
+ getSuggestions ( {
129
+ ...defaultOptions ,
130
+ selectedItem : [
131
+ { id : 1 , value : 'one' } ,
132
+ { id : 2 , value : 'two' } ,
133
+ ] ,
134
+ allowCreate : true ,
135
+ } ) ( '' )
136
+ ) . toEqual ( [
137
+ { id : 3 , value : 'three' } ,
138
+ { id : '@@create' , value : 'ra.action.create' } ,
139
+ ] ) ;
140
+ } ) ;
141
+
113
142
it ( 'should limit the number of choices' , ( ) => {
114
143
expect (
115
144
getSuggestions ( {
Original file line number Diff line number Diff line change @@ -226,11 +226,13 @@ export const getSuggestionsFactory = ({
226
226
matchSuggestion ( filter , suggestion , true )
227
227
) ;
228
228
229
- const filterIsSelectedItem = ! ! selectedItem
230
- ? matchSuggestion ( filter , selectedItem , true )
231
- : false ;
232
-
233
229
if ( allowCreate ) {
230
+ const filterIsSelectedItem =
231
+ // If the selectedItem is an array (for example AutocompleteArrayInput)
232
+ // we should't try to match
233
+ ! ! selectedItem && ! Array . isArray ( selectedItem )
234
+ ? matchSuggestion ( filter , selectedItem , true )
235
+ : false ;
234
236
if ( ! hasExactMatch && ! filterIsSelectedItem ) {
235
237
suggestions . push (
236
238
getSuggestion ( {
You can’t perform that action at this time.
0 commit comments