How can i use Material UI Autocomplete with tags and react-final-form at the same time

Viewed 39

export const AutocompleteFreeSolo: React.FC<{ source: string; initialValue?: string }> = ({
  source,
  initialValue,
}) => {
  return (
    <Field type="text" name={source} defaultValue={initialValue}>
      {({ input, meta, ...rest }) => {
        return (
          <>
            <Autocomplete
              multiple
              id="tags-filled"
              options={top100Films.map((option: any) => option.title)}
              freeSolo
              renderTags={(value: readonly string[], getTagProps) => {
                return value.map((option: string, index: number) => (
                  <Chip variant="outlined" label={option} {...getTagProps({ index })} />
                ));
              }}
              renderInput={(params) => (
                <TextField {...params} variant="filled" label="freeSolo" placeholder="Favorites" />
              )}
            />
          </>
        );
      }}
    </Field>
  );
};

I am using something like this. But I dont know how to pass value from Field to Autocomplete. I need to get a string from the server and format the string separated by commas and each word should be a Chip. If someone helps me i will be very grateful

0 Answers
Related