@@ -21,6 +21,7 @@ export function FormAutocomplete({
21
21
filter,
22
22
disabled : _disabled ,
23
23
afterChange,
24
+ allowUnlistedValue,
24
25
} ) {
25
26
const { getValue, setValue : _setValue , register, isValid, getFormSubmitedAttempted, getFormData } = useFormControl (
26
27
name
@@ -98,6 +99,8 @@ export function FormAutocomplete({
98
99
setValue ( '' ) ;
99
100
setSelectedItem ( null ) ;
100
101
updateSearchInputValidation ( ) ;
102
+ } else if ( isEmptyLike ( selectedItem ) && ! isEmptyLike ( searchValue ) && allowUnlistedValue ) {
103
+ onSelectItem ( { value : searchValue , label : searchValue } ) ;
101
104
}
102
105
103
106
if ( ignoreBlur ) {
@@ -106,7 +109,17 @@ export function FormAutocomplete({
106
109
close ( ) ;
107
110
setFocus ( false ) ;
108
111
}
109
- } , [ close , ignoreBlur , searchValue , setValue , updateSearchInputValidation , value ] ) ;
112
+ } , [
113
+ close ,
114
+ ignoreBlur ,
115
+ searchValue ,
116
+ setValue ,
117
+ updateSearchInputValidation ,
118
+ value ,
119
+ onSelectItem ,
120
+ allowUnlistedValue ,
121
+ selectedItem ,
122
+ ] ) ;
110
123
111
124
const enableSearchInput = useCallback ( ( ) => {
112
125
if ( disabled ) {
@@ -201,6 +214,7 @@ FormAutocomplete.defaultProps = {
201
214
202
215
FormAutocomplete . propTypes = {
203
216
afterChange : PropTypes . func ,
217
+ allowUnlistedValue : PropTypes . bool ,
204
218
disabled : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
205
219
filter : PropTypes . func ,
206
220
id : PropTypes . string ,
@@ -227,6 +241,7 @@ export function FormGroupAutocomplete(props) {
227
241
228
242
FormGroupAutocomplete . propTypes = {
229
243
afterChange : PropTypes . func ,
244
+ allowUnlistedValue : PropTypes . bool ,
230
245
disabled : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . func ] ) ,
231
246
filter : PropTypes . func ,
232
247
help : PropTypes . node ,
0 commit comments